我有一个sure设置,可以从标准的DNN 'Files‘表中获取所有具有特定扩展名的文档,但是我想添加一个额外级别的规范,说明要显示的文件类别,但不确定如何最好地实现它。请参见下面的代码:
@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";
}
}我希望将2 2sxc类别实体与DNN的Tab/Page分类法标记/类别同步,以便用户在页面设置中选择DNN标记,如果与2 2sxc类别实体同步,该标记将允许我将特定的doc/excel/pdf文件(已经通过2 2sxc连接到2 2sxc类别)分配到基于select的应用程序,该应用程序通过将taxonomy_terms表与内容项表连接起来,然后与与DNN选项卡表连接的内容项标记表连接。
如何更正下面的LINQ/Razor代码,以筛选我的类别,使其只显示指定给它们的确切“服务”类别的文件。我将使用此筛选器与分类法标签'Services‘(完全匹配)同步,我想将其链接到2 2sxc类别(它已经通过2 2sxc连接到已上载的Adam文件)和DNN分类法术语'Services'?
@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注释,并且我一直在使用使用stuck模板的foreach来获得类别筛选器的正确语法。
干杯..。
发布于 2017-05-16 08:16:36
是的,我需要的过滤器如下所示:
@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>再次感谢!
发布于 2017-05-15 18:14:16
我相信我们已经用邮件解决了这个问题。
一个次要的建议是:如果您使用DnnSqlDataSource而不是SqlDataSource,那么您的当前DNN已经有了正确的连接字符串。也见http://2sxc.org/en/docs/Feature/feature/4670和https://github.com/2sic/2sxc/wiki/DotNet-DataSources-All
https://stackoverflow.com/questions/43496570
复制相似问题