【发布时间】:2017-04-19 13:03:04
【问题描述】:
我有一个 SQL 数据源设置,可以从标准 DNN“文件”表中获取具有特定扩展名的所有文档,但我想添加一个额外级别的规范来说明要显示的文件类别,但不确定如何最好地进行它。请参阅下面我当前的 SQL 数据源代码:
@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";
}
}
我想将 2sxc 类别实体与 DNN 的选项卡/页面分类标签/类别同步,以允许用户在页面设置上选择 DNN 标记(如果与 2sxc 类别实体同步)将允许我分配一个特定的 doc/excel/pdf 文件(已经通过 2sxc iCache 连接到 2sxc 类别)到基于 SQL 数据源的应用程序,该应用程序通过将 taxonomy_terms 表与内容项表连接,然后与内容项标签表连接DNN 选项卡表。
如何更正下面的 LINQ/Razor 代码以过滤我的类别以仅显示分配给它们的确切“服务”类别的文件。我将使用此过滤器与我想使用 DNN 分类术语“服务”链接到 2sxc 类别(已上传的 Adam 文件已通过 2sxc iCache 连接)的分类标记“服务”(完全匹配)同步?
@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 上的 wiki 注释,并且我坚持使用带有 SQL 数据源模板的 foreach 来获取类别过滤器的正确语法。
干杯...
【问题讨论】:
标签: linq razor datasource 2sxc