我有一个可以生成查询并将其导出到 Excel 的方法。我希望用户选择他们想要导出的列。
我的问题有点类似于这个 OP LINQ select property by name
我们可以在其中基于列表创建LINQ 选择查询string[] columns,它应该与下面的_dbcontext.Person.Select( SelectorFunc(columns) ).SomeOtherQuery().ToList();
查询和函数有点相似SelectorFunc(columns)
public Func<Person, string[]> SelectorFunc(string[] columns) {
// ninja code!!
return " not sure here";
}
Run Code Online (Sandbox Code Playgroud)
如果我必须像这样手动完成它,那就有点混乱了。
var query = _dbcontext.Person.AsQueryable();
if(column == "ID")
query = query.Select( x=x.ID);
if(column == "Name")
query = query.Select( x=x.Name);
//and the list goes on...
Run Code Online (Sandbox Code Playgroud)
PS:我真的很感谢您的启发,也感谢您的宝贵时间。
我有一个多个区域,我想将我的布局指向我的共享区域文件夹。我的文件夹是
App
-...
-Model
-...
-Controller
-...
-View
|-Shared
- _layout.cshtml <--- root layout
- _layout2.cshtml <--- workaround
- _ViewStart.cshtml <--- OK!
-Areas
|-Areaname1
|-Controllers
|-Views
|-Shared
- _layout.cshtml <--- my area layout
- _ViewStart.cshtml <--- i want to use the layout above
|-Areaname2
-...
Run Code Online (Sandbox Code Playgroud)
我里面的代码Areas Views/ _ViewStart.chtml
@{
// Layout = "~/Views/Shared/_Layout.cshtml"; <--- will point on the root layout
// Layout = "~/Views/Shared/_Layout2.cshtml"; <--- view to root
// Layout = "~Area/Areaname1/Views/Shared/_Layout.cshtml"; <--- correct path
// Layout = "~/Areaname1/Views/Shared/_Layout.cshtml"; …Run Code Online (Sandbox Code Playgroud)