Note that there are some explanatory texts on larger screens.

plurals
  1. POMerge Two or More Entity Framework Entities with Dynamic Columns?
    primarykey
    data
    text
    <p>I've got a project that uses an SQLite database with Entity Framework and VB.Net. The database is complex but everything is set up well for accessing the data in individual tables. </p> <p>What I need is a way to transform (pivot?) the data from two or more tables and get a resulting table with columns that are generated dynamically based on the data in the original tables. As an example, if I start with two tables that look like this:</p> <pre><code>Table 1 Id Data Field 1 17 1 1 34 2 1 72 3 2 23 1 2 11 2 2 46 3 3 1 1 3 19 2 3 24 3 Table 2 Id Data Field 1 abc 4 1 def 5 1 ghi 6 2 jkl 4 2 mno 5 2 pqr 6 3 stu 4 3 vwx 5 3 yz 6 </code></pre> <p>I need to end up with the following as the resulting table:</p> <pre><code>Id Field1 Field2 Field3 Field4 Field5 Field6 1 17 34 72 abc def ghi 2 23 11 46 jkl mno pqr 3 1 19 24 stu vwx yz </code></pre> <p>Simplified, obviously, but I hope the general layout is clear. At design time I do <strong>not</strong> know how many fields (and thus columns in the resulting merged table) there will be. I do know, however, that all the Data in Table 1 will be numeric and all the Data in Table 2 will be text.</p> <p>Obviously I can loop through the data and construct a DataTable dynamically in code, but I'm trying to figure out if there's a more efficient way to do it, that can be used with data binding to a datagrid. I've tried various LINQ Joins (using System.Linq.Dynamic) but I always run into problems with the fact that I don't know how many of the fields there will be.</p> <p>Another important factor is that this data will need to be editable, so when the user updates a value I'll need to have some way to figure out which row in which original table is being edited.</p> <p>Does anybody have any ideas?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload