I am new to DataObjects. I read its documents and searched the website, but I didn't find a way to create/extend an entity at run time. For I let end users to add some attributes(fields), even some entities (tables) at run time in UI layer, I need such a feature to make my story true. A fake statments may be the following: EntityBuilder b=new EntityBuilder() ... Just like TypeBuilder in System.Refelection.Emit. Thanks, Ying This thread was imported from our support forum. The original discussion may contain more detailed answer. Original topic by thinkly. |
mahdness wrote:I was thinking about this same idea the other day... Does it offer any benefits over the traditional approach of adding an EntitySet<customvalues> property to your entities? I guess one benefit is that you can index by these fields since they would be in the same DB table Dmitri Maximov (Xtensive) wrote:Hello guys, Let me introduce one of the DataObjects.Net 4 unknown treasures. ;) Probably, you've already met IModule interface but haven't known the purpose of OnDefinitionsBuild method. Let me remind you the signature:
As one might knows, Domain model building process consists of 2 phases: during the first one we build definitions of persistent types, fields, indexes, etc. (this is so-called 'Definition model'), whereas during the second phase we construct full-fledged model objects such as TypeInfo, FieldInfo, IndexInfo, AssociationInfo and everything. The reason why we're using such a 2-phase process is that we want to allow user-code to get a control over Definition model and make all necessary changes to it in right time in right place. The method I'm talking about (OnDefinitionsBuilt) is exactly for this purpose. It allows you to redefine anything in the Definition model, even to create it from scratch. Let's look at the following example:
Notice that the process is being taken place during the Domain build procedure. So it is not in pure runtime as you may think as DO 4 need complete and built model to perform database schema upgrade at the very beginning of its work. Hope that helps. P.S. Is such a material worth inclusion in DO Samples or at least publishing with more details in DO blog? It might be a bit specific & geek-oriented, imho. |