我有一个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 Categories实体与DNN的Tab / Page Taxonomy标签/类别同步,以便允许用户在页面设置上选择DNN标签(如果与2sxc Categories实体同步)将允许我分配特定的doc / excel / pdf文件(已通过2sxc iCache连接到2sxc类别)到基于SQL数据源的应用程序,该数据源通过将taxonomy_terms表与内容项表连接,然后连接到内容项标签表连接DNN标签表。
如何更正下面的LINQ / Razor代码以过滤我的类别,只显示分配了确切“服务”类别的文件。我将使用此过滤器与分类标签“服务”(完全匹配)同步,我想链接到2sxc类别(其中已经通过2sxc iCache连接的已上传的Adam文件)与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上的wiki说明,并且我坚持使用带有SQL数据源模板的foreach来获取类别过滤器的正确语法。
干杯...
答案 0 :(得分:1)
我相信我们已经通过邮件解决了这个问题。
一个小建议:如果您使用DnnSqlDataSource而不是SqlDataSource,那么您已经拥有了当前DNN的正确连接字符串。另请参阅http://2sxc.org/en/docs/Feature/feature/4670以及https://github.com/2sic/2sxc/wiki/DotNet-DataSources-All
答案 1 :(得分:0)
是的,我需要的过滤器如下所示:
@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>
再次感谢!