Filling a DataSet or DataTable from a LINQ query result set

后端 未结 7 713
一个人的身影
一个人的身影 2020-12-01 02:38

How do you expose a LINQ query as an ASMX web service? Usually, from the business tier, I can return a typed DataSet or DataTable which can be seri

相关标签:
7条回答
  • 2020-12-01 03:15

    To perform this query against a DataContext class, you'll need to do the following:

    MyDataContext db = new MyDataContext();
    IEnumerable<DataRow> query = 
        (from order in db.Orders.AsEnumerable()
            select new
            {
                order.Property,
                order.Property2
            })
        as IEnumerable<DataRow>;
    return query.CopyToDataTable<DataRow>();
    

    Without the as IEnumerable<DataRow>; you will see the following compilation error:

    Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' to 'System.Collections.Generic.IEnumerable'. An explicit conversion exists (are you missing a cast?)

    0 讨论(0)
提交回复
热议问题