开发者

Problem building a custom object off an XML column/string using Entity Framework repository to POCO

I'm using Entity Framework 4.0 within a repository pattern to populate my POCO objects which are in another assembly. One of my objects contains an XML column from the database (a string type on the class).

Unfortunately, this XML string contains primary key IDs that I need to THEN use to retrieve other objects (with the repository) to build another custom object. I've been trying to do this using a custom get accessor on the domain object that tries to parse the XML and then go fetch from the repository. The pr开发者_StackOverflow中文版oblem is that this results in my model requiring the repository and gives me a circular dependency.

Is there any good way to do something like this? Perhaps some custom code to parse the XML column within the EF repository layer and map what I need to on a custom object in my model??

Any responses are greatly appreciated, thank you!


No there is no way to tell EF that XML column is actually other entity type. Once you move the logic to the get accessor you indeed break create model dependency on persistence which is something you are trying to remove by using POCOs. It will break your domain driven desing.

In domain driven design loading objects is strict responsibility of repository. So you need to build your retrieval method in the way that allows you to request loading related entities, for example:

  • load main object, parse XML and load relations in the same repository method
  • or load main object in single method and parse XML and load relations in another method

If the main object is not aggregate root for relations (they can exists separately) you should create separate repository for related objects and expose method just to load objects defined by XML string.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜