开发者

LinqToSql Join with a table and a view

I have a table described as

CREATE TABLE [dbo].[Project](
[id] [int] IDENTITY(1,1) NOT NULL,
[WRSA_ID] [varchar](9) NOT NULL,
[Administrator] [varchar](5) NOT NULL

And a view described as

CREATE VIEW [dbo].[ProjectView]
AS
SELECT     Project_ID, Project_Name
FROM         WRSA.dbo.projects

The WRSA_ID in Project is actually a foreign key of Project_ID in ProjectView but obviously since the table is referencing a view I can't place a foreign key constraint on the table. In the UI I have both entities Project and ProjectView开发者_JAVA百科 but due to the lack of foreign key, there is no physical link between them.

I want to select all Projects where a search string is found either in the WRSA_ID/Project_ID or in the Project_Name or Administrator. How would I do this is LinqToSql?


I believe you can include both the table and the view in your .DBML and then manually add a relationship between the two. Even if you can't, this won't prevent you from querying the tables as if they were joined. You just need to add a Linq 'join', to tell Linq how the tables should be joined together. Something like this:

from project in Project
join projectView in ProjectView on project.WRSA_ID equals projectView.Project_ID
where...
select...
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜