First of all: I'm new to EF, and it's just checking the capabilities of EF and seeing how it fits into an environment that is already defined in terms of database tables and an object model - and when these two models do not display 1: 1 in terms of class names / table names and attribute names / column names and even the number of tables and classes. Please keep the “feature check” in mind if you feel like responding: “EF is not intended to be used that way.” Thank you :)
Consider the following scenario.
I have three database tables:
|----------------| |-------------| |-----------------| | MessageLog | >---1 | Message | 1---< | MessageText | |----------------| |-------------| |-----------------| | logId | | messageId | | messageId | | messageId | | type | | languageCode | | from | | ... | | text1 | | to | |-------------| | text2 | | ... | | ... | |----------------| |-----------------|
What I want to map to two classes:
|--------------------| |----------------------------| | ServiceMessage |<-\ | ServiceMessageInstance | |--------------------| | |----------------------------| | Id: string | | | Id: string | | LanguageCode: str. | \----| Message: ServiceMessage | | Text1: string | | From: DateTime | | Text2: string | | To: DateTime | | Type: MessageType | |----------------------------| |--------------------|
ServiceMessage objects consist of a row from the message table (with the key messageId ) and a row from the MessageText table (with messageId and languageCode as).
ServiceMessageInstance is simpler: it refers to a ServiceMessage object and some additional attributes.
I played a little with EF and did a lot of search queries, but I did not find the answer to my question: how can I do this with EF? Which approach should I take? Can I do this with an EDMX designer? DbContext.OnModelCreating?
I understand that this may be too broad a question, but I would appreciate any pointers!
Thanks.
BR, Herms
herms source share