简体   繁体   中英

c# entity framework 5 code first map three part table name to entity

Does anybody know if EF5 allows you to specify a three part name when mapping an entity to a table?

The situation is, I have one database server (a single instance) with two databases on it, one of the database can't be changed due to the support agreement, and the other database is completely under my control.

Sorry I can't share the schema of the databases.

So I would like a Linq query like this:

from t1 in dbContext.TableOne
join t2 in dbContext.TableTwo on t1.Id equals t2.Id
select new { ... }

to produce a SQL query like this:

SELECT
   *
FROM
   DbOne.dbo.TableOne AS T1
   JOIN
   DbTwo.dbo.TableTwo AS T2
      ON T1.Id = T2.Id

If its not possible I'll just use two DbContext's, I would just prefer having the one context.

This feature does not exist in Entity Framework. There is a change request that currently has status "Under Review" (which can mean anything, but at least it's not rejected - yet).

The closest you can get is using synonyms as described here . But synonyms are easily broken!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM