Filling a DataSet or DataTable from a LINQ query result set

后端 未结 7 818
一个人的身影
一个人的身影 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:11

    If you use IEnumerable as the return type, it will return your query variable directly.

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

提交回复
热议问题