2sxc | SQL数据源-LINQ筛选器查询
我有一个SQL数据源设置,可以从标准DNN“Files”表中获取具有特定扩展名的所有文档,但我想添加一个额外级别的规范,说明要显示的文件类别,但不确定如何最好地执行。请参见下面我当前的SQL数据源代码:2sxc | SQL数据源-LINQ筛选器查询,linq,razor,datasource,2sxc,Linq,Razor,Datasource,2sxc,我有一个SQL数据源设置,可以从标准DNN“Files”表中获取具有特定扩展名的所有文档,但我想添加一个额外级别的规范,说明要显示的文件类别,但不确定如何最好地执行。请参见下面我当前的SQL数据源代码: @using ToSic.Eav.DataSources @functions { // Default data initialization - should be the place to write data-retrieval code // In the future
@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";
}
}
@使用ToSic.Eav.DataSources
@功能
{
//默认数据初始化-应该是编写数据检索代码的地方
//将来完全实施布线和管道时,这通常是一个仅限外部配置的系统
//目前,它是在一个正常事件中完成的,该事件由2SexyContent中的razor主机自动调用
公共覆盖无效自定义数据()
{
var source=CreateSource();
//source.TitleField=“EntityTitle”;//不需要,默认值
//source.EntityIdField=“EntityId”;//不需要,默认值
//source.ConnectionString=“…”;//不需要,我们正在下一行使用ConnectionString名称
source.ConnectionStringName=Content.ConnectionName;
//特别注意:我不是从数据库中选择*的,因为我正在激活JSON,并希望确保没有机密数据传出
source.SelectCommand=“从PortalId=@PortalId AND Extension='docx'或Extension='xlsx'或Extension='pdf'的文件中,选择前10名的FileId作为EntityId,FileName作为EntityTitle,PublishedVersion,UniqueId,FileName,Size作为大小,Extension作为扩展名,CreatedOnDate作为日期,Folder作为文件夹;
Add(“@PortalId”,Dnn.Portal.PortalId.ToString());
Data.In.Add(“FileList”,source.Out[“Default”]);
//启用发布
Data.Publish.Enabled=true;
Data.Publish.Streams=“默认,文件列表”;
}
}
我想将2sxc Categories实体与DNN的选项卡/页面分类标记/类别同步,以便允许用户在页面设置中选择一个DNN标记(如果与2sxc Categories实体同步),这将允许我分配一个特定的doc/excel/pdf文件(已通过2sxc iCache连接到2sxc类别)到基于SQL数据源的应用程序,该应用程序通过将分类法_术语表与内容项表连接,然后再与与DNN tabs表连接的内容项标记表连接
我如何更正下面的LINQ/Razor代码,以过滤我的类别,使其仅显示指定了确切“服务”类别的文件。我将使用此筛选器与分类法标记“服务”(精确匹配)同步,我希望将其链接到带有DNN分类法术语“服务”的2sxc类别(已通过2sxc iCache连接了已上载的Adam文件)
@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>
}
@foreach(AsDynamic中的var文件(Data.in[“FileList”])。其中(i=>
(i.Category as List).Any(c=>c.EntityId==FileList.EntityId)))
{
@file.FileName
}
我已经详细阅读了上的wiki注释,我一直在使用foreach和SQL数据源模板获取类别过滤器的正确语法
干杯…我相信我们已经通过邮件解决了这个问题
一个次要的建议是:如果使用DnnSqlDataSource而不是SqlDataSource,那么您已经拥有了当前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>
@使用ToSic.SexyContent
@{
//所有QandA项目
var all=AsDynamic(应用程序数据[“QandA”]列表);
//可以在模板中设置筛选值
//但通常您可以通过请求[“urlparam”]从url获取它
//或者从视图中的设置中,使用Content.Category
var currentCat=“业务”;
//筛选,查找任何具有当前类别的
var过滤=全部
其中(p=>(p.Categories作为列表).Any(c=>AsDynamic(c.Name==currentCat));
}
@foreach(过滤后的var q)
{
@编辑工具栏(内容)
@q、 头衔
}
再次感谢