2017-04-19 73 views
0

我有一個SQL數據源設置,以獲得從標準DNN「文件」表中的某個擴展的所有文件,但我想在哪個類別的文件中添加指定額外級別的顯示,但不知道如何最好地去做。見我當前的SQL數據源代碼如下:2sxc | SQL數據源 - LINQ過濾查詢

@using ToSic.Eav.DataSources 
@functions 
{ 
    // Default data initialization - should be the place to write data-retrieval code 
    // In the future when routing & pipelines are fully implemented, this will usually be an external configuration-only system 
    // For now, it's done in a normal event, which is automatically called by the razor host in 2SexyContent 
    public override void CustomizeData() 
    { 
     var source = CreateSource<SqlDataSource>(); 
     // source.TitleField = "EntityTitle"; // not necessary, default 
     // source.EntityIdField = "EntityId"; // not necessary, default 
     // source.ConnectionString = "..."; // not necessary, we're using the ConnectionStringName on the next line 
     source.ConnectionStringName = Content.ConnectionName; 

    // Special note: I'm not selecting * from the DB, because I'm activating JSON and want to be sure that no secret data goes out 
    source.SelectCommand = "Select Top 10 FileId as EntityId, FileName as EntityTitle, PublishedVersion, UniqueId, FileName, Size as Size, Extension as Extension, CreatedOnDate as Date, Folder as Folder FROM Files WHERE PortalId = @PortalId AND Extension = 'docx' OR Extension = 'xlsx' OR Extension = 'pdf'"; 
    source.Configuration.Add("@PortalId", Dnn.Portal.PortalId.ToString()); 
    Data.In.Add("FileList", source.Out["Default"]); 

    // enable publishing 
    Data.Publish.Enabled = true; 
    Data.Publish.Streams = "Default,FileList"; 
    } 
} 

我要同步與DNN的標籤/頁分類標籤的2sxc分類實體/類別,以便允許用戶選擇在頁面設置一個DNN標籤,它(如果同步與2sxc分類實體)將允許我分配一個特定DOC/EXCEL/PDF文件(通過2sxc ICACHE已經連接到2sxc類別),以在此基礎上通過與內容項目表中加入taxonomy_terms表連接的SQL數據源的應用並依次與連接到DNN選項卡表的內容項目標籤表相關聯。

我怎樣才能更正我下面的LINQ /剃刀代碼到我的類別過濾器與分配給他們確切的「服務」類別只顯示文件。我將使用此過濾器與分類標籤「服務」(精確匹配),我想鏈接到2sxc類別(已上傳的亞當文件已經通過2sxc ICACHE連接)與DNN分類術語「服務」同步?

@foreach (var file in AsDynamic(Data.In["FileList"]).Where(i => 
     (i.Category as List<dynamic>).Any(c => c.EntityId == FileList.EntityId))) 
     { 
      <li>@file.FileName</li> 
     } 

我已經看過了詳細的關於https://github.com/2sic/2sxc/wiki/DotNet-Query-Linq維基筆記,我被困在得到該類別過濾器正確的語法使用與SQL數據源模板的foreach。

乾杯......

回答

0

是的,我需要的過濾器是爲你提供如下!

1

我相信,我們通過郵件已經解決了這一點。

一個小小的建議:如果你使用的,而不是在SqlDataSource DnnSqlDataSource你已經爲你的當前DNN正確的連接字符串。再次

@using ToSic.SexyContent 

    @{ 
    // all QandA items 
    var all = AsDynamic(App.Data["QandA"].List); 

    // the filter value, can be set in template 
    // but usually you would either get it from url with Request["urlparam"] 
    // or from a setting in the view, using Content.Category 
    var currentCat = "Business"; 

    // filter, find any which have the current category 
    var filtered = all 

    .Where(p => (p.Categories as List<DynamicEntity>).Any(c => AsDynamic(c).Name == currentCat)); 

} 

<div class="clearfix"> 
     @foreach (var q in filtered) 
     { 
      <div class="sc-element" data-tags="@String.Join(",", ((List<DynamicEntity>)q.Categories).Select(a => AsDynamic(a).EntityId))"> 

       @Edit.Toolbar(Content) 

       <div class="col-md-12"> 
        <div class=""> 
         <a href="@q.Link" class=""> 
          <span class="">@q.Link</span> 
         </a> 
         <p>@q.Title</p> 
        </div> 
       </div> 
      </div> 
     } 
</div> 

感謝:又見http://2sxc.org/en/docs/Feature/feature/4670以及https://github.com/2sic/2sxc/wiki/DotNet-DataSources-All

+0

我會深入瞭解一下DnnSqlDataSource,THX! – denisjoconnor