Loading a DataSet or DataTable from a LINQ question result set

Just how do you reveal a LINQ question as an ASMX internet solution? Generally, from business rate, I can return a keyed in DataSet or DataTable which can be serialized for transportation over ASMX.

Just how can I do the very same for a LINQ question? Exists a means to inhabit a keyed in DataSet or DataTable using a LINQ question?

public static MyDataTable CallMySproc()
{
    string conn = "...";

    MyDatabaseDataContext db = new MyDatabaseDataContext(conn);
    MyDataTable dt = new MyDataTable();

    // execute a sproc via LINQ
    var query = from dr
                in db.MySproc().AsEnumerable
                select dr;

    // copy LINQ query resultset into a DataTable -this does not work !    
    dt = query.CopyToDataTable();

    return dt;
}

Just how can I get the outcome set of a LINQ question right into a DataSet or DataTable? Conversely, is the LINQ question serializable to make sure that I can reveal it as an ASMX internet solution?

0
2019-05-06 23:55:19
Source Share
Answers: 4

Make a set of Data Transfer Objects, a number of mapmakers, and also return that using the.asmx.
You need to never ever reveal the data source things straight, as an adjustment in the procedure schema will certainly circulate to the internet solution customer without you seeing it.

0
2019-12-03 04:33:39
Source

As stated in the inquiry, IEnumerable has a CopyToDataTable method :

IEnumerable<DataRow> query =
    from order in orders.AsEnumerable()
    where order.Field<DateTime>("OrderDate") > new DateTime(2001, 8, 1)
    select order;

// Create a table from the query.
DataTable boundTable = query.CopyToDataTable<DataRow>();

Why will not that benefit you?

0
2019-12-03 04:29:14
Source

Create a class object and also return a list(T) of the question.

0
2019-05-17 20:15:34
Source

If you make use of a return sort of IEnumerable, you can return your question variable straight.

0
2019-05-08 20:40:16
Source