Linq to SQL - Return DataTable as a result of Linq query

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • szwejk

    Linq to SQL - Return DataTable as a result of Linq query

    Hi!

    How to get result od dataTable from Linq query? I have typied DataSet
    and I want to join couple of tables. And I have a problem with change
    this result to DataTable type. (I don't want to rewrite everything in
    foreach)

    e.g. How can I make DataTable from it? Thx for help!

    var query =
    from firmy in boKontakty.Data SetKontakty.FIR MY
    join kancelarie in
    boKontakty.Data SetKontakty.KAN CELARIE on firmy.FIRMA_O equals
    kancelarie.ID into firmKan
    join kategorie in
    boKontakty.Data SetKontakty.KAT EGORIE on firmy.KATEGORIA equals
    kategorie.NAZWA into firmKanKat
    select
    new
    {
    Id = firmy.ID,
    Nazwa = firmy.NAZWA,
    Nazwa_pelna = firmy.NAZWA_PEL NA,
    Kancelaria_obsl ugujaca = kancelarie.NAZW A,
    Kolor = kategorie.KOLOR
    };
  • Alberto Poblacion

    #2
    Re: Linq to SQL - Return DataTable as a result of Linq query

    "szwejk" <szwejkc@gmail. comwrote in message
    news:7b80c573-4656-4afd-a598-70e67202f749@f4 7g2000hsd.googl egroups.com...
    How to get result od dataTable from Linq query? I have typied DataSet
    and I want to join couple of tables. And I have a problem with change
    this result to DataTable type. (I don't want to rewrite everything in
    foreach)
    The standard libraries do not contain such a functionality, but it
    shouldn't be terribly difficult to write an Extension method for
    IEnumerable<Tre turning a DataTable, using Reflection to enumerate the
    properties of T and creating a DataTable (or filling an existing one) with
    equivalent columns. Of course, the internal implementation would have to use
    foreach to populate the table, but this would be invisible to you once the
    extension method was created.


    Comment

    Working...