开发者

two tables considered as one

I have two tables like this:

Table1(id, name)
Table2(id_of_table_1, code)

I don't need an entity for Table1 or Table2, but one entity for both together:

class Merge{
    public virtual long id{get;set;}
    public virtual string name{get;set;}
    public virtual string code{get;set;}
}

How can I load the tables to the edmx so that they will considered as one?

I don't have any control on the database and I开发者_运维问答 can't create tables or views.


You are looking for advanced mapping called Entity splitting.


I think this is what you're lookig for: How to: Define a Model with a Single Entity Mapped to Two Tables


In short, you need to do this:

  1. Add the two tables as two separate entities to your model
  2. Cut the scalar values from the Table2 entity to the Table1 entity
  3. Delete the Table2 entity
  4. In the Table Mapping options of the Table1 entity, map the Table2-fields to Table2

For a more detailed explanation, you can have a look at this blog post.


Create a function inside your Merge class that writes the properties of your class to the appropriate Table1 and Table2 EDMX objects. Your Merger class should have references to those EDMX objects as internal variables. So this class is like a wrapper for your 2 table objects.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜