MushinNoShin
MushinNoShin

Reputation: 4886

Class composition in Entity Framework 4

Say I have a very simple class structure, more for convenience than anything.

class A{
    [Column("someValue")]
    public int someValue{get; set;}
}

[Table("tableB")]
class B{
    [Column("somethingElse")]
    public int somethingElse{get; set;}
    public A somethingEncapsulated{get; set;}
}

[Table("tableC")]
class C{
    [Column("otherSomething")]
    public int otherSomething{get; set;}
    public A somethingEncapsulated{get; set;}
}

And the database structure, which cannot be changed looks so

tableB
------
somethingElse int
someValue int

tableC
-----
otherSomething int
someValue int

Is it possible to represent this structure in Entity Framework without eliminating class A? If so, how?

Upvotes: 1

Views: 2041

Answers (1)

Eranga
Eranga

Reputation: 32447

You can use complex type mapping in this scenario.

[ComplextType]
public class A{
    [Column("someValue")]
    public int someValue{get; set;}
}

Go through this article

Upvotes: 3

Related Questions