开发者

Entity key of a view as navigation property

开发者 https://www.devze.com 2022-12-08 00:28 出处:网络
I have a table CREATE TABLE Tasks ( ID INT IDENTITY(1,1) NOT NULL CONSTRAINT PRIMARY KEY PkTasks, ...other fields...

I have a table

CREATE TABLE Tasks
( 
    ID INT IDENTITY(1,1) NOT NULL CONSTRAINT PRIMARY KEY PkTasks,
    ...other fields...
)

and a view

CREATE VIEW VTaskInfo
AS
SELECT
 开发者_运维技巧   T.ID IDTask,
    ...other fields...
FROM
    Tasks T

How can I create navigation property connecting 'Task' and 'VTaskoInfo' entities? Usually defining navigation properties requires deleting id property, but this time property is primary key and can't be deleted. I could change VTaskInfo definition to

CREATE VIEW VTaskInfo
AS
SELECT
    T.ID IDTask,
    T.ID ID,
    ...other fields...
FROM 
    Tasks T

and specify ID as entity key and IDTask as navigation property, but I don't like this solution. Is there something else I can do?

How do you map views in EF?


Here's an article regarding using EF and DB Views:

http://smehrozalam.wordpress.com/2009/08/12/entity-framework-creating-a-model-using-views-instead-of-tables/

0

精彩评论

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