EntityCollection to DataSet

Posts   
 
    
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 11-Nov-2004 09:55:46   

Greetings,

Is there a generic way of converting an Entity collection to a DataSet. I thought this to be a trivial task but then I realized that an object (in an EntityCollection) could have one more child collections as properties. In this case the object graph should be converted to a collection of related data tables that are contained in the data set.

It would be nice if FRANS builds a (.ToDataSet) method in the entity collection to expose this functionality...

OMAR

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 11-Nov-2004 10:59:42   

And how should m:1 and 1:1 related entities be represented, also in a separate datatable?

Frans Bouma | Lead developer LLBLGen Pro
arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 11-Nov-2004 14:28:54   

That would be a good way to do it.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 11-Nov-2004 18:44:08   

There is a problem then simple_smile

Datasets are set-based containers. This means that if you have an entity collection of Orders and each order has a loaded customer object, the only way to store this is to create two datatables, one for orders and one for customers and 1 datarelation. This is perhaps nice, but you then lose the obvious a-contained-in-b hierarchy you had with the order - customer hierarchy in the orders collection.

It's not that bad though, but it's a different way of looking at the data. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Fabrice
User
Posts: 180
Joined: 25-May-2004
# Posted on: 12-Nov-2004 10:52:03   

I wrote it, and the main problem is not m:1 or 1:1 relations but m:n relations. Yes it'll be usefull I think but also time consuming. The schemas creation take most of the time. It's why it can be usefull to make a : - public DataSet ToDataSet() : generate the schema and fill with data - public void FillDataSet(DataSet ds) : only fill the dataset (suppose that the schema is allready made) So that we can create dataset first time, store the schemas in the project so that we can onli use the FillDataSet method to take less time.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 12-Nov-2004 11:07:15   

But why would you fill a dataset? There is already a way to fill a datatable with entity data (like fetching a list of entities into a datatable).

Frans Bouma | Lead developer LLBLGen Pro
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 12-Nov-2004 22:19:44   

Frans... how would do that.. by looping through a collection and filling a data table or is there another way I don't know about flushed

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 13-Nov-2004 14:49:33   

omar wrote:

Frans... how would do that.. by looping through a collection and filling a data table or is there another way I don't know about flushed

Directly from the database?

Adapter:


// get all customers in a datatable. If you need a filter, just specify it as a 3rd parameter
// to FetchTypedList
CustomerEntity c = new CustomerEntity();
DataTable customers = new DataTable();
adapter.FetchTypedList(c.Fields, customers, null);

SelfServicing:


DataTable customers = CustomerCollection.GetMultiAsDataTable(null, 0, null);

Frans Bouma | Lead developer LLBLGen Pro
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 13-Nov-2004 23:27:59   

Thanks Frans.. this is exactly what I was looking for.

I thought that TypedLists are only created from Views flushed

LLBL rules sunglasses

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 15-Nov-2004 10:39:33   

omar wrote:

Thanks Frans.. this is exactly what I was looking for.

I thought that TypedLists are only created from Views flushed

Heh, no those are typed views! simple_smile . Typed Lists are multi-entity views based on entities, which you can design in the designer. simple_smile The routine to fetch them can also be used to fetch data based on a set of fields into a datatable simple_smile

LLBL rules sunglasses

smile

Frans Bouma | Lead developer LLBLGen Pro
Fabrice
User
Posts: 180
Joined: 25-May-2004
# Posted on: 15-Nov-2004 17:37:48   

Otis wrote:

But why would you fill a dataset? There is already a way to fill a datatable with entity data (like fetching a list of entities into a datatable).

Well but what about if your entity is linked to several other entities ? you have to fill a dataset with several tables, not a datatable. And the final touch is that you have to put primary keys and foreign keys.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 15-Nov-2004 18:14:42   

Ok, good point, my only question is then: why would you need that dataset setup if you have entity collections? (just to understand where functionality is lacking in the generated code). Design time support is now covert with the new design time support code now in release candidate phase simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Fabrice
User
Posts: 180
Joined: 25-May-2004
# Posted on: 16-Nov-2004 14:45:52   

I work througth webservices, and I dont use entities because : - dataset generate much more compact xml than llblgen entity serialization (yes we allready spoke about that simple_smile ) - I don't want to install llblgen libraries on the client side (update problem to synchronize client and server version etc).

PS : Well, if the feature is only for me it's useless simple_smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 16-Nov-2004 15:24:24   

Ok good point. I'll see what I can do.

Frans Bouma | Lead developer LLBLGen Pro