开发者

Saving and retrieving inherited types with LINQtoSQL and Business Objects

开发者 https://www.devze.com 2022-12-20 07:28 出处:网络
I have an abstract EventBase class and some inherited event types, along with an Event class.Each event type has its own unique columns.

I have an abstract EventBase class and some inherited event types, along with an Event class. Each event type has its own unique columns.

In my data layer, I have a GetEvents method that simply does:

from e in db.Events
    select new Event {...values...};

EventType is an enum which matches up to an Eve开发者_运维知识库ntTypes table

I want GetEvents(EventType type) and GetEvent(int id, EventType type) to do something like..

from e in GetEvents()
    where e.TypeId == (int)type
    select new TypeSpecified {...values for Event + Type-specific fields...};

// Determine what type it is
// Switch statement? Dictionary?

I'm not sure a switch is the best idea, but I'm also not sure how to correctly employ a dictionary to map the data retrieval and object creation to a specific type.

My second question involves saving the data - going from Business Object to L2S table - same question as above, basically

I hope this makes sense :)


The page from Rick Strahl helpped me to get my business layer up and running. This might be a good start for you too.

http://www.west-wind.com/weblog/posts/160237.aspx

My main problem was that I tend to over engineer the business layer. So one have to keep it simple but not to simple ;-)

0

精彩评论

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