Export Model to DataTable

前端 未结 3 981
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-02 02:25

I want to convert my Model data to DataSet or DataTable (to export in excel format)

db.EMPs.ToList()

db

3条回答
  •  忘掉有多难
    2020-12-02 03:26

    You can use ToDataTable extension method but you need to install MoreLinq first. To install MoreLINQ, run the following command in the Package Manager Console:

    PM> Install-Package morelinq

    Then add the following line to your using directives:

    using MoreLinq;
    

    And finally you can use ToDataTable extension method:

    DataTable s = db.EMPs.ToDataTable();
    

提交回复
热议问题