开发者

How do Entitiy Framework support 'Derivative Entities' and business rules on the conceptual layer?

Saying "Derivative entities" I mean those "domain objects" that cannot be directly mapped with DB tables but still开发者_如何学运维 exists "between rows" and can be reconstructed using aggregation/ranking rules.

Example: I have a table where records have two dateTimes for time period management. Using complex but still natural rule based on the interpretation of those periods union and some other fields, we group those records into Episodes. Those "Episodes" or "aggregated records" are quite popular objects in my domain, so I am searching for the way how to organize the code flexible way.

What could Entity Framework propose to me? Could I somehow declare those "Episodes" on the conceptual model? Or from the ORM tool point of view those "domain objects" are always "yet another query"?

Now I construct those Eisodes using 'ad hoc' types with linq expression and "foreach" cycle (to get aggregated values). I call this code "the business rule", but without covered 'declaration' on the conceptual layer this 'business rule' is just 'the code' :)

PS It would be better to have those Episodes in the DB but it is impossible now... PPS Entity Framework 4.1


One way of thinking about this is that you have a non-persisted domain object called Episode that aggregates entities that are persisted. Entities that are part of your model (the ones that are persisted) are "members" of an Episode based on logic relating to the timestamp fields.

One approach would be to define an Episode class that aggregates these model entities. The Episode class need not be aware of the persistence of the model objects- in fact, the POCO template removes persistence awareness from the persisted model objects as well.

The strategy for "assigning" a model object to an Episode will depend on the logic involved. You could add a static method to the Episode class that takes a model object as a parameter. That method could then apply the assignment logic, instantiating new Episodes and assigning the model objects to them as appropriate.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜