Linq to sql convert IQueryable to Dataset

What is the easiest way to convert an IQueryable to a dataset?

+3
source share
4 answers

modelshredder has exactly what you need. If you have a datacontext and don’t need data from the point of view of your model, the nitzmahone solution is excellent performance (if it matches your setup, which is not clear to me)

+3
source

(yourDatacontext) .GetCommand (yourIQueryableHere), pass the command text to the DbCommand object, call ExecuteReader, pass the reader to the data set. Boot method.

+2
source

IDataReader, IEnumerable (IQueryable IEnumberable). . DataTable.Load(IDataReader).

0

DataTable , LINQ to Sql, , IQueryable DataTable:

public static DataTable AsDataTable(this IQueryable value, DataTable table)
{
    var reader = value.GetEnumerator();

    while (reader.MoveNext())
    {
        var record = (Customer)reader.Current;
        table.Rows.Add(record.CustomerID, record.City);
    }

    return table;
}

, - TEntity:

[Table(Name = "Customers")]
public class Customer
{
    [Column(IsPrimaryKey = true)]
    public string CustomerID;
    [Column]
    public string City;
}

, DataTable Customer. , , :

public DataTable GetSchema(params string[] columns)
{
    string col_list;

    if (columns.Length == 0)
        col_list = "*";
    else
        col_list = String.Join(", ", columns);

    return Provider.QueryAsDataTable(string.Format("select top 0 {0} from customers", col_list));
}

, DataGridView:

    dgridRO.DataSource = new DataView(rows.AsDataTable(dmap.GetSchema("CustomerID", "City")));


**

ID10TException:

** IQueryable DataTable, DataView DataGridView. , , .

0

Source: https://habr.com/ru/post/1719413/


All Articles