开发者

Is it possible to have multiple Entity Framework edmx's with a shared connection string?

My concept is to have a logging/audit edmx file with corresponding mapped types defined in one project. This edmx has concepts and classes like AuditTrail and PropertyChange

A second edmx for the actual application models, domain if you will, with classes like Product, Category, and Order.

What I want to do is "scoop up" the first auditing edmx file into the second domain edmx. The schema information is 100% the same, the database has tables from both.

What I want to have happen is that these two edmx files are combined in such a way that I can use a transaction to save data such as both are dependent on each other finishing. My audit information can't save without my domain information and vice versa.

I've been goggling around and this seems possible I'm just missing some implementation detail thats not bringing this together.

This should be as simple as pointing the domain edxm and objectcontext connection string to the auditing edmx's csdl, ssdl, and msl files? The goal would be to load all of the MetaData information inside a single instance of an ObjectContext so I can wrap a call to both with a transaction.

This is what I have in my connection string for the web app/domain part of this application:

                      connectionString="metadata=res://*/Mod开发者_JS百科els.CfarModels.csdl|
                                                 res://*/Models.CfarModels.ssdl|
                                                 res://*/Models.CfarModels.msl|
                                                 W:\map\AuditModels.csdl|
                                                 W:\map\AuditModels.ssdl|
                                                 W:\map\AuditModels.msl;

Am I on the right track here is is this impossible?


While it is possible to load multiple CSDL files into one (Entity)Connection, it is not possible to load multiple MSL or SSDL files, because these are completely self-contained.

Back to the CSDL, there is a rarely used <using> element in CSDL. Which might give the impression that it is similar to a Reference in .NET, but actually it is more like a Merge.

I.e. one CSDL in another actually modifies both, merging them together, and potentially invalidates MSL's and SSDL's, by making them incomplete.

So back to your scenario:

You could in theory have 2 CSDLs: 1) To describe the Audit types 2) That uses (1) & defines the Domain Types and defines EntitySets and AssociationSets for both kinds of types.

You would then have one mapping file to map (2) and a storage model file too.

Which would leave you with something like this:

"metadata=res://*/Models.CfarModels.csdl|
          res://*/Models.CfarModels.ssdl|
          res://*/Models.CfarModels.msl|
          W:\map\AuditModel.csdl;

Personally though I don't think you gain enough from this separation to make it worthwhile, most of the metadata is in the extents, the mapping and the storage model anyway, so type re-use while nice is only about 20% of the work anyway.

All you can really re-use is the audit type definitions, but that probably isn't worth the effort.

Hope this helps

Alex James

Microsoft.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜