【问题标题】:Implementing Dynamic LINQ querying in MVC5/EF Application?在 MVC5/EF 应用程序中实现动态 LINQ 查询?
【发布时间】:2015-03-11 06:46:26
【问题描述】:

作为概述,我正在尝试将Export() 功能添加到我的应用程序中——允许用户指定某些模型字段并仅通过使用LINQ 查询并使用EPPlus 库导出这些字段中的值。我正在尝试基于THIS 示例在我的 MVC5/EF Code-First 应用程序中实现动态 LINQ 功能,但似乎缺少一些东西以使其工作或不理解某些东西。

首先,我在我的主项目文件夹中添加了一个名为DynamicLibrary.cs 的新类文件。当我下载 .zip HERE 时,我“相信”我想要的代码是我在项目中复制到 DynamicLibrary.cs 中的 Dynamic.cs 文件代码。这样做让我可以在我的项目中引用using System.Linq.Dynamic

现在我一直在努力弄清楚如何为 Dynamic LINQ 设置其余部分。

在我的ExportControllernamespace InventoryTracker.Controllers {} 但在public class ExportController : Controller { } 之外,我根据我尝试导出的INV_Assets 模型中的字段添加了示例代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using InventoryTracker.DAL;
using OfficeOpenXml;
using InventoryTracker.Models;
using System.Linq.Dynamic;


namespace InventoryTracker.Controllers
{
    public class ExportController : Controller
    {
        InventoryTrackerContext _db = new InventoryTrackerContext();

        // GET: Export
        public ActionResult Index()
        {
            ExportAssetsViewModel expViewMod = new ExportAssetsViewModel();
            return View(expViewMod);
        }

        public ActionResult Export()
        {
            GridView gv = new GridView();
            gv.DataSource = _db.INV_Assets.ToList();
            gv.DataBind();
            Response.ClearContent();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment; filename=InventoryAssets-" + DateTime.Now + ".xls");
            Response.ContentType = "application/ms-excel";
            Response.Charset = "";
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            gv.RenderControl(htw);
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();

            return RedirectToAction("StudentDetails");
        }

        [HttpPost]
        public ActionResult ExportUsingEPPlus(ExportAssetsViewModel model)
        {
            //FileInfo newExcelFile = new FileInfo(output);
            ExcelPackage package = new ExcelPackage();
            var ws = package.Workbook.Worksheets.Add("TestExport");  

            var exportFields = new List<string>();
            foreach(var selectedField in model.SelectedFields)
            {
                // Adds selected fields to [exportFields] List<string>
                exportFields.Add(model.ListOfExportFields.First(s => s.Key == selectedField).Value);
            }

            // Loops to insert column headings into Row 1 of Excel
            for (int i = 0; i < exportFields.Count(); i++ )
            {
                ws.Cells[1, i + 1].Value = exportFields[i].ToString();
            }

            // INVALID - Need to query table INV_Assets for all values of selected fields and insert into appropriate columns.
            if (exportFields.Count() > 0)
            {
                var exportAssets = from ia in _db.INV_Assets
                                   select new {
                                       ia.ip_address,

                                   }
                ws.Cells["A2"].LoadFromCollection(exportFields);
            }

            var memoryStream = new MemoryStream();
            package.SaveAs(memoryStream);

            string fileName = "Exported-InventoryAssets-" + DateTime.Now + ".xlsx";
            string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

            memoryStream.Position = 0;
            return File(memoryStream, contentType, fileName);
        }

    }

    public class DynamicColumns : INV_Assets
    {
        //public int Id { get; set; }
        //public int Model_Id { get; set; }
        public virtual INV_Models Model { get; set; }
        //public int Manufacturer_Id { get; set; }
        public virtual INV_Manufacturers Manufacturer { get; set; }
        //public int Type_Id { get; set; }
        public virtual INV_Types Type { get; set; }
        //public int Location_Id { get; set; }
        public virtual INV_Locations Location { get; set; }
        //public int Vendor_Id { get; set; }
        public virtual INV_Vendors Vendor { get; set; }
        //public int Status_Id { get; set; }
        public virtual INV_Statuses Status { get; set; }
        public string ip_address { get; set; }
        public string mac_address { get; set; }
        public string note { get; set; }
        public string owner { get; set; }
        public decimal cost { get; set; }
        public string po_number { get; set; }
        public string description { get; set; }
        public int invoice_number { get; set; }
        public string serial_number { get; set; }
        public string asset_tag_number { get; set; }
        public DateTime? acquired_date { get; set; }
        public DateTime? disposed_date { get; set; }
        public DateTime? verified_date { get; set; }
        public DateTime created_date { get; set; }
        public string created_by { get; set; }
        public DateTime? modified_date { get; set; }
        public string modified_by { get; set; }
    }

    public enum EnumTasks
    {
        Model = 1,
        Manufacturer = 2,
        Type = 3,
        Location = 4,
        Vendor = 5,
        Status = 6,
        ip_address = 7,
        mac_address = 8,
        note = 9,
        owner = 10,
        cost = 11,
        po_number = 12,
        description = 13,
        invoice_number = 14,
        serial_number = 15,
        asset_tag_number = 16,
        acquired_date = 17,
        disposed_date = 18,
        verified_date = 19,
        created_date = 20,
        created_by = 21,
        modified_date = 22,
        modified_by = 23
    }

     public IQueryable DynamicSelectionColumns()
    {
        using (var db = new TrackerDataContext())
        {
            string fieldIds = "," + "4,5,3,2,6,17,11,12" + ",";

            var taskColum = Enum.GetValues(typeof(EnumTasks)).Cast<EnumTasks>().Where(e => fieldIds.Contains("," + ((int)e).ToString() + ",")).Select(e => e.ToString().Replace("_", ""));

            string select = "new (  TaskId, " + (taskColum.Count() > 0 ? string.Join(", ", taskColum) + ", " : "") + "Id )";

            return db.Task.ToList().Select(t => new DynamicColumns() { Id = t.Id, TaskId = Project != null ? Project.Alias + "-" + t.Id : t.Id.ToString(), ActualTime = t.ActualTime, AssignedBy = t.AssignedBy.ToString(), AssignedDate = t.AssignedDate, AssignedTo = t.AssignedTo.ToString(), CreatedDate = t.CreatedDate, Details = t.Details, EstimatedTime = t.EstimatedTime, FileName = t.FileName, LogWork = t.LogWork, Module = t.Module != null ? t.Module.Name : "", Priority = t.Priority != null ? t.Priority.Name : "", Project = t.Project != null ? t.Project.Name : "", ResolveDate = t.ResolveDate, Status = t.Status != null ? t.Status.Name : "", Subject = t.Subject, TaskType = t.TaskType != null ? t.TaskType.Type : "", Version = t.Version != null ? t.Version.Name : "" }).ToList().AsQueryable().Select(select);
        }
    }
}

我不是 100% 确定它设置在正确的位置。下面最后一个方法有5个错误:

  • IQueryable - Expected class, delegate, enum, interface, or struct.
  • InventoryTrackerContext - Expected class, delegate, enum, interface, or struct.
  • DynamicColumns() - Expected class, delegate, enum, interface, or struct.
  • public IQueryable DynamicSelectionColumns()关闭} - Type or namespace definition, or end-of-file expected.
  • namespace InventoryTracker.Controllers关闭} - Type or namespace definition, or end-of-file expected.

    public IQueryable DynamicSelectionColumns()
    {
        using (var db = new InventoryTrackerContext())
        {
            string fieldIds = "," + "4,5,3,2,6,17,11,12" + ",";
    
            var taskColum = Enum.GetValues(typeof(EnumTasks)).Cast<EnumTasks>().Where(e => fieldIds.Contains("," + ((int)e).ToString() + ",")).Select(e => e.ToString().Replace("_", ""));
    
            string select = "new (  TaskId, " + (taskColum.Count() > 0 ? string.Join(", ", taskColum) + ", " : "") + "Id )";
    
            return db.Task.ToList().Select(t => new DynamicColumns() { Id = t.Id, TaskId = Project != null ? Project.Alias + "-" + t.Id : t.Id.ToString(), ActualTime = t.ActualTime, AssignedBy = t.AssignedBy.ToString(), AssignedDate = t.AssignedDate, AssignedTo = t.AssignedTo.ToString(), CreatedDate = t.CreatedDate, Details = t.Details, EstimatedTime = t.EstimatedTime, FileName = t.FileName, LogWork = t.LogWork, Module = t.Module != null ? t.Module.Name : "", Priority = t.Priority != null ? t.Priority.Name : "", Project = t.Project != null ? t.Project.Name : "", ResolveDate = t.ResolveDate, Status = t.Status != null ? t.Status.Name : "", Subject = t.Subject, TaskType = t.TaskType != null ? t.TaskType.Type : "", Version = t.Version != null ? t.Version.Name : "" }).ToList().AsQueryable().Select(select);
        }
    }
    

在这种事情上有更多经验的人可以称重吗?我还查看了ScottGu's Blog,但似乎缺少或不理解某些内容。


编辑

已删除空间


EDIT2

使用从DynamicSelectionColumns() 到我的变量selectStatement 的返回,我有以下编码:

    public IQueryable DynamicSelectionColumns(List<string> fieldsForExport)
    {
        using (var db = new InventoryTrackerContext())
        {
            string fieldIds = "," + "4,5,3,2,6,17,11,12" + ",";

            var taskColum = Enum.GetValues(typeof(EnumTasks)).Cast<EnumTasks>().Where(e => fieldIds.Contains("," + ((int)e).ToString() + ",")).Select(e => e.ToString().Replace("_", ""));

            //string select = "new (  TaskId, " + (taskColum.Count() > 0 ? string.Join(", ", taskColum) + ", " : "") + "Id )";
            string select = "new (  " + string.Join(", ", fieldsForExport) + ")";

            //return db.INV_Assets.ToList().Select(t => new DynamicColumns() { Id = t.Id, TaskId = Project != null ? Project.Alias + "-" + t.Id : t.Id.ToString(), 
             return db.INV_Assets.ToList().Select(t => new DynamicColumns() { 
                Id = t.Id, 
                Manufacturer = Convert.ToString(t.Manufacturer.manufacturer_description), 
                Type = t.Type.type_description, 
                Location = t.Location.location_room, 
                Vendor = t.Vendor.vendor_name, 
                Status = t.Status.status_description, 
                ip_address = t.ip_address, 
                mac_address = t.mac_address, 
                note = t.note, 
                owner = t.owner, 
                //Module = t.Module != null ? t.Module.Name : "", 
                cost = t.cost,
                po_number = t.po_number,
                description = t.description,
                invoice_number = t.invoice_number,
                serial_number = t.serial_number,
                asset_tag_number = t.asset_tag_number,
                acquired_date = t.acquired_date,
                disposed_date = t.disposed_date,
                verified_date = t.verified_date,
                created_date = t.created_date,
                created_by = t.created_by,
                modified_date = t.modified_date,
                modified_by = t.modified_by
            }).ToList().AsQueryable().Select(select);
        }
    }

    [HttpPost]
    public ActionResult ExportUsingEPPlus(ExportAssetsViewModel model)
    {
        ExcelPackage package = new ExcelPackage();
        var ws = package.Workbook.Worksheets.Add("TestExport");  

        var exportFields = new List<string>();
        foreach(var selectedField in model.SelectedFields)
        {
            // Adds selected fields to [exportFields] List<string>
            exportFields.Add(model.ListOfExportFields.First(s => s.Key == selectedField).Value);
        }

        var selectStatement = DynamicSelectionColumns(exportFields);

        // Loops to insert column headings into Row 1 of Excel
        for (int i = 0; i < exportFields.Count(); i++ )
        {
            ws.Cells[1, i + 1].Value = exportFields[i].ToString();
        }

        if (selectStatement.Count() > 0)
        {
            ws.Cells["A2"].LoadFromCollection(selectStatement.ToString());
        }

        var memoryStream = new MemoryStream();
        package.SaveAs(memoryStream);

        string fileName = "Exported-InventoryAssets-" + DateTime.Now + ".xlsx";
        string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

        memoryStream.Position = 0;
        return File(memoryStream, contentType, fileName);
    }

这会产生一个 Excel 输出,其中包含 [ip_address]、[mac_address]、[note]、[owner] 和 [cost] 列(我选择的字段),但没有数据。我在 A 列中得到 251 行 0 而不是数据,而在其他列中没有。

如何在我的 Excel 电子表格中实现动态选择查询结果?


EDIT3

尝试ThulasiRam 的建议(下面的ExportController):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using InventoryTracker.DAL;
using OfficeOpenXml;
using InventoryTracker.Models;
using System.Linq.Dynamic;


namespace InventoryTracker.Controllers
{
    public class ExportController : Controller
    {
        InventoryTrackerContext _db = new InventoryTrackerContext();
        public static List<DynamicColumns> DynamicColumnsCollection = new List<DynamicColumns>();

        [HttpPost]

public ActionResult ExportUsingEPPlus(ExportAssetsViewModel 模型) { //FileInfo newExcelFile = new FileInfo(output); ExcelPackage 包 = 新 ExcelPackage(); var ws = package.Workbook.Worksheets.Add("TestExport");

    var exportFields = new List<string>();
    foreach(var selectedField in model.SelectedFields)
    {
        // Adds selected fields to [exportFields] List<string>
        exportFields.Add(model.ListOfExportFields.First(s => s.Key == selectedField).Value);
    }

    int cnt = 0;
    foreach(var column in exportFields)
    {
        DynamicColumnsCollection.Add(new DynamicColumns()
        {
            Id = cnt,

            ip_address = "ip_address" + cnt,
            mac_address = "mac_address" + cnt,
            note = "note" + cnt,
            owner = "owner" + cnt,
            cost = "cost" + cnt,
            po_number = "po_number" + cnt,
            description = "description" + cnt,
            invoice_number = "invoice_number" + cnt,
            serial_number = "serial_number" + cnt,
            asset_tag_number = "asset_tag_number" + cnt,
            acquired_date = "acquired_date" + cnt,
            disposed_date = "disposed_date" + cnt,
            verified_date = "verified_date" + cnt,
            created_date = "created_date" + cnt,
            created_by = "created_by" + cnt,
            modified_date = "modified_date" + cnt,
            modified_by = "modified_by" + cnt
        });
    }

    //var selectStatement = DynamicSelectionColumns(exportFields);
    IQueryable collection = DynamicSelectionColumns(new List<string>() {
        "id",
        "owner",
        "note"
    });

    // Loops to insert column headings into Row 1 of Excel
    for (int i = 0; i < exportFields.Count(); i++ )
    {
        ws.Cells[1, i + 1].Value = exportFields[i].ToString();
    }

    ws.Cells["A2"].LoadFromCollection(collection.ToString());

    //    ws.Cells["A2"].LoadFromCollection(selectStatement.ToString());

    var memoryStream = new MemoryStream();
    package.SaveAs(memoryStream);

    string fileName = "Exported-InventoryAssets-" + DateTime.Now + ".xlsx";
    string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

    memoryStream.Position = 0;
    return File(memoryStream, contentType, fileName);
}

        public IQueryable DynamicSelectionColumns(List<string> fieldsForExport)
        {
            using (var db = new InventoryTrackerContext())
            {

                if (!fieldsForExport.Any())
                {
                    return null;
                }

                string select = string.Format("new ( {0} )", string.Join(", ", fieldsForExport.ToArray()));

                var collection = DynamicColumnsCollection.Select(t => new DynamicColumns()
                    {
                        Id = t.Id,
                        //Manufacturer = Convert.ToString(t.Manufacturer.manufacturer_description),
                        //Type = t.Type.type_description,
                        //Location = t.Location.location_room,
                        //Vendor = t.Vendor.vendor_name,
                        //Status = t.Status.status_description,
                        ip_address = t.ip_address,
                        mac_address = t.mac_address,
                        note = t.note,
                        owner = t.owner,
                        //Module = t.Module != null ? t.Module.Name : "", 
                        cost = t.cost,
                        po_number = t.po_number,
                        description = t.description,
                        invoice_number = t.invoice_number,
                        serial_number = t.serial_number,
                        asset_tag_number = t.asset_tag_number,
                        acquired_date = t.acquired_date,
                        disposed_date = t.disposed_date,
                        verified_date = t.verified_date,
                        created_date = t.created_date,
                        created_by = t.created_by,
                        modified_date = t.modified_date,
                        modified_by = t.modified_by
                    }).ToList().AsQueryable().Select(select);

                return collection;


        }

    }

    public class DynamicColumns : INV_Assets
    {
        public string Model { get; set; }
        public string Manufacturer { get; set; }
        public string Type { get; set; }
        public string Location { get; set; }
        public string Vendor { get; set; }
        public string Status { get; set; }
        public string ip_address { get; set; }
        public string mac_address { get; set; }
        public string note { get; set; }
        public string owner { get; set; }
        public string cost { get; set; }
        public string po_number { get; set; }
        public string description { get; set; }
        public string invoice_number { get; set; }
        public string serial_number { get; set; }
        public string asset_tag_number { get; set; }
        public string acquired_date { get; set; }
        public string disposed_date { get; set; }
        public string verified_date { get; set; }
        public string created_date { get; set; }
        public string created_by { get; set; }
        public string modified_date { get; set; }
        public string modified_by { get; set; }
    }

    public enum EnumTasks
    {
        Model = 1,
        Manufacturer = 2,
        Type = 3,
        Location = 4,
        Vendor = 5,
        Status = 6,
        ip_address = 7,
        mac_address = 8,
        note = 9,
        owner = 10,
        cost = 11,
        po_number = 12,
        description = 13,
        invoice_number = 14,
        serial_number = 15,
        asset_tag_number = 16,
        acquired_date = 17,
        disposed_date = 18,
        verified_date = 19,
        created_date = 20,
        created_by = 21,
        modified_date = 22,
        modified_by = 23
    }

我不知道在我的 MVC 应用程序中从他们的建议(或设置)中将这段相关代码放在哪里:

    static void Main(string[] args)
    {
        IQueryable collection = DynamicSelectionColumns(new List<string>() { "id", "name" });

        Console.ReadLine();
    }

有什么想法吗?我不确定如何构造我的 MVC 应用程序示例中使用的 static Program()Main()。在我上面列出的代码中(我应该只选择note/owner 字段),我收到一个输出Excel 表,其中A1 中的"note"B1 中的"owner",然后只是数字@ 987654364@ 在单元格A2:A180...?

【问题讨论】:

  • 不确定我现在是否理解您的问题。你能澄清一下吗?
  • 关于选择fieldIdsGetValues()taskColumselect 的部分。 select(如果我读的是正确的话)通过计算 taskColum 变量的值并使用它们的 fieldId? 来构建 select 查询。示例代码正在寻找TaskId,我不确定所有需要修改的内容以供我自己使用——我相信我已经为return 正确设置代码,但第一部分仍然让我有点丢失的。我不确定如何使用DynamicSelectionColumns() 函数来动态搜索我的字段。

标签: c# asp.net-mvc linq entity-framework epplus


【解决方案1】:

您遇到的错误与 linq 或您导入项目的其他库无关。

您是在命名空间中声明函数 DynamicSelectionColumns,而不是在 ExportController 类中。

编辑后:

如果您的 exportFields 已经是 Task 列的列表,您只需将该列表传递给 DynamicSelectionColumns 并将其包含在里面:

string select = "new (  " + string.Join(", ", exportFields) + ")";

编辑后2:

替换

ws.Cells["A2"].LoadFromCollection(selectStatement.ToString());

ws.Cells["A2"].LoadFromCollection(selectStatement, false);

编辑后3:

经过这种反复试验后,我决定确实查找您提到的 EPPlus 库。我发现您不需要任何动态查询。您可以在LoadFromCollection 中指定要显示的字段。 我没有编译这个(因为它是你的代码),但它在我的机器上用假数据工作。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.IO;
    using InventoryTracker.DAL;
    using OfficeOpenXml;
    using InventoryTracker.Models;
    using System.Reflection;
    using OfficeOpenXml.Table;


    namespace InventoryTracker.Controllers
    {
        public class ExportController : Controller
        {
            private InventoryTrackerContext _db = new InventoryTrackerContext();

            [HttpPost]
            public ActionResult ExportUsingEPPlus(ExportAssetsViewModel model)
            {
                //FileInfo newExcelFile = new FileInfo(output);
                ExcelPackage package = new ExcelPackage();
                var ws = package.Workbook.Worksheets.Add("TestExport");

                var exportFields = new List<string>();
                foreach (var selectedField in model.SelectedFields)
                {
                    // Adds selected fields to [exportFields] List<string>
                    exportFields.Add(model.ListOfExportFields.First(s => s.Key == selectedField).Value);
                }

                // Loops to insert column headings into Row 1 of Excel
                for (int i = 0; i < exportFields.Count(); i++)
                {
                    ws.Cells[1, i + 1].Value = exportFields[i].ToString();
                }

                var membersToShow = typeof(INV_Asset).GetMembers()
                    .Where(p => exportFields.Contains(p.Name))
                    .ToArray();

                ws.Cells["A2"].LoadFromCollection(_db.INV_Assets.ToList(), false, TableStyles.None, BindingFlags.Default, membersToShow);


                var memoryStream = new MemoryStream();
                package.SaveAs(memoryStream);

                string fileName = "Exported-InventoryAssets-" + DateTime.Now + ".xlsx";
                string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

                memoryStream.Position = 0;
                return File(memoryStream, contentType, fileName);
            }
        }
    }

【讨论】:

  • 感谢您的回复!我已经按照您的建议移动了课程,这消除了我之前列出的错误,但我仍在尝试弄清楚如何设置动态 LINQ 代码供我自己使用。请参阅上面的编辑。
  • 关于“编辑后”:一旦我打电话给DynamicSelectionColumns(List&lt;string&gt; exportFields),我在返回时该怎么办?如何根据用户选择的字段对INV_Assets 进行实际查询?
  • 请看我上面的EDIT2。
  • 关于“编辑后2”:ws.Cells["A2"].LoadFromCollection(selectStatement, false); 产生"The type arguments for method 'OfficeOpenXml.ExcelRangeBase.LoadFromCollection&lt;T&gt;(System.Collections.Generic.IEnumerable&lt;T&gt;)' cannot be inferred from the usage. Try specifying the type arguments explicitly."....?
  • 这是一个很长的镜头,但您可以尝试ws.Cells["A2"].LoadFromCollection(selectStatement.Cast&lt;object&gt;(), false); 获取 IQueriable 的通用版本。
【解决方案2】:
1. TaskId property not exist in DynamicColumns class.

2. Remove .Replace("_", "") from
   var taskColum = Enum.GetValues(typeof(EnumTasks)).Cast<EnumTasks>().Where(e => fieldIds.Contains("," + ((int)e).ToString() + ",")).Select(e => e.ToString().Replace("_", ""));

3.exportFields.Count should be > 0.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic;

namespace Dynamic
{
    public class Program
    {
        public static List<DynamicColumns> DynamicColumnsCollection = new List<DynamicColumns>();

        static Program()
        {
            for (int i = 0; i < 10; i++)
            {
                DynamicColumnsCollection.Add(new DynamicColumns() { Id = i, Name = "Name" + i, ip_address = "ip_" + i });
            }
        }

        static void Main(string[] args)
        {
            IQueryable collection = DynamicSelectionColumns(new List<string>() { "id", "name" });

            Console.ReadLine();
        }

        public class DynamicColumns
        {
            public int Id { get; set; }

            public string Name { get; set; }

            public string ip_address { get; set; }
        }

        public static IQueryable DynamicSelectionColumns(List<string> fieldsForExport)
        {
            if (!fieldsForExport.Any())
                return null;

            string select = string.Format("new ( {0} )", string.Join(", ", fieldsForExport.ToArray()));

            var collection = DynamicColumnsCollection.Select(t => new DynamicColumns()
            {
                Id = t.Id,
                Name = t.Name,
                ip_address = t.ip_address,
            }).ToList().AsQueryable().Select(select);

            return collection;
        }
    }
}

如有任何问题,请告诉我。

问候,

Ram.S

【讨论】:

  • 感谢您的回复。我似乎在弄清楚如何在我的 MVC 应用程序中设置您在 Program()/Main() 中使用的代码时遇到了一些麻烦。请参阅我上面的 EDIT3。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-20
  • 1970-01-01
  • 2016-01-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多