开发者

Generating ADO.NET Entity Data Model files, where to start?

开发者 https://www.devze.com 2022-12-09 16:14 出处:网络
Our product is partially built using Delphi and partially .NET and in our current state of migration to .NET, we have the data dictionary in a Delphi component, so this is the master.

Our product is partially built using Delphi and partially .NET and in our current state of migration to .NET, we have the data dictionary in a Delphi component, so this is the master.

From this we generate .NET source code through templating, to support simple querying but also to do Linq2Sql, since our product requires SQL Server.

However, I'd like to switch to the new Entity model in .NET instead of Linq2Sql, but I don't know how much work that would be. All the tutorials or examples I find seem to revolve around modelling the data model in the designer, or getting it from the database, neither works for our needs.

In Linq2Sql, we annotated our query-classes with TableMappingAttribute and ColumnMappingAttribute, and then generated a descendant of DataContext, this all works very well.

Is there a similar easy path to get to use the Entity model code 开发者_开发技巧instead? Or do I have to produce all those xml files and run tools to produce resources, etc.?

Has anyone been in the same situation and can shed some light on this?


Unfortunately for you I think you do need the XML files.

There are actually 3 files that make up the EDM. (although in visual studio they are all combined into 1 EDMX file)

  • ssdl - storage (Describes the database)
  • csdl - conceptual (Describes data objects)
  • msl - mapping (Describes the mapping between storage and conceptual)

From the EDM files, the EDM Generator can be used to generate all three from a database connection, just the msl and csdl from the ssdl, or it can generate the actual data objects from the csdl.

Unfortunately though, that isn't where the usage of the XML stops. It is still needed at runtime for the entity framework to perform the translation from objects to storage etc. A reference to the 3 EDM files must be provided in the Entity framework connection string. (More info on building EF connection strings)

You could probably come up with ways to have your data object code generated (or automatically tag your existing ones with the various required attributes and extra methods) - like Linq there are attributes like EdmEntityTypeAttribute and EdmScalarPropertyAttribute that are put on the classes and properties, but without the 3 EDM files the entity framework isn't going to know what to do with your data objects. The generator also adds other stuff to the data objects classes like property changed events, and an inheritance from EntityObject. I'm not sure what of the extra stuff is required for correct operation of the entity framework, and what is just there for the developer. I would assume the property changes events are required by the data context to track changes.

There's an article here on EDM tools and some code for generating/splitting EDMX files into their component ssdl/csdl/msl files.

0

精彩评论

暂无评论...
验证码 换一张
取 消