Create/Extend entities at runtime?

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
moslembd
Posts: 2
Joined: Sat 03 Nov 2012 10:57

Create/Extend entities at runtime?

Post by moslembd » Sat 03 Nov 2012 11:02

Hi,

I was wondering if it is possible to create/extend entities at runtime. My application is Data-Oriented and will massively use entities created by the end user.

This would be something similar to Artificial Types in OpenAccess (http://www.telerik.com/help/openaccess- ... types.html) but I prefer using LinqConnect for performance reasons.

Best regards

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Create/Extend entities at runtime?

Post by MariiaI » Tue 06 Nov 2012 14:42

LinqConnect doesn't have such a functionality. However, you could create new types,e.g. via the reflection, and use the XML mapping (it could be the XML file, that is pre-created or created at runtime) or the Fluent mapping.

We are sending you a sample project, that demonstrates creating a new entity type at runtime and the use of XML mapping, to the e-mail address you provided in your forum profile. Please check that is not blocked by your mail filter.
Please tell us if this helps.

moslembd
Posts: 2
Joined: Sat 03 Nov 2012 10:57

Re: Create/Extend entities at runtime?

Post by moslembd » Tue 06 Nov 2012 21:39

Hi,

Thank you for your input and for the sample project. That actually partially replied to my needs. What is restricting me in your sample is :

1. The entity class must be already created and compiled (not really a run-time definition), a complex alternative I am considering is to create the classes using CodeDOM
2. The database schema must be updated separately, I will have to generate an alter script and run it before ever using the mapping. Each modification to the entity XML should trigger an alter operation.
3. I never tried multiple context in the same application and I will have to conduct some performance testing on that.

It would be helpful if you tell me if the SQL generation API is exposed, I never tried to look for that.

Thank you!

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Create/Extend entities at runtime?

Post by MariiaI » Thu 08 Nov 2012 14:46

In the sample, we are working with a Type variable, so the sample doesn't exploit the fact that our type is pre-defined. When, e.g., creating a new type via reflection, you can get the corresponding Type variable as well and use it in the exactly same way we did in the sample.

As for altering the database, you could send 'alter' SQL scripts to the database via the DataContext.ExecuteCommand method.
Unfortunately, you would have to prepare these scripts on your own. DataContext can only recreate the whole database, you can use for this DataContext.CreateDatabase() and DataContext.DeleteDatabase() methods.
For more information please refer to:
http://www.devart.com/linqconnect/docs/ ... mmand.html
http://www.devart.com/linqconnect/docs/ ... abase.html
http://www.devart.com/linqconnect/docs/ ... abase.html

As for the multiple contexts, DataContext is designed as a lightweight object and creating new DataContext objects shouldn't reduce the performance significantly. In fact, it is recommended to use one DataContext per unit-of-work, especially if the latter includes modifying data. Mapping cannot be changed for existing DataContext objects, because it can contribute the data corruption of the objects that were cached by this context.

HadleyHope
Posts: 8
Joined: Thu 24 Jan 2013 14:44

Re: Create/Extend entities at runtime?

Post by HadleyHope » Thu 24 Jan 2013 14:55

MariiaI wrote:LinqConnect doesn't have such a functionality. However, you could create new types,e.g. via the reflection, and use the XML mapping (it could be the XML file, that is pre-created or created at runtime) or the Fluent mapping.

We are sending you a sample project, that demonstrates creating a new entity type at runtime and the use of XML mapping, to the e-mail address you provided in your forum profile. Please check that is not blocked by your mail filter.
Please tell us if this helps.
Would it be possible to make the sample public or send also send me the sample project? I have a similar use case in that I would like to use LinqConnect but most database tables will need to be created at runtime depending on the data the user imports. The tables will all have the same structure but the table name indicates the contents classification. The data is split by classification as there can be millions of rows per classification but a database may only contain a few classifications (which are not known until the user imports the data from flat files).

Thanks

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Re: Create/Extend entities at runtime?

Post by StanislavK » Fri 25 Jan 2013 17:37

We've sent a sample to you, please check that the letter is not blocked by your mail filter.

Post Reply