Naor
Naor

Reputation: 24053

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.

Upvotes: 4

Views: 198

Answers (4)

Kristof Claes
Kristof Claes

Reputation: 10941

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.

Upvotes: 1

bniwredyc
bniwredyc

Reputation: 8829

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

Upvotes: 1

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364249

You are looking for advanced mapping called Entity splitting.

Upvotes: 2

Tony The Lion
Tony The Lion

Reputation: 63190

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.

Upvotes: 0

Related Questions