…is not a foreign key column and cannot be used he

2019-08-16 11:15发布

问题:

I have two views in SQL, and have created mappings to them in Linq to SQL.

The two views have an association, which works fine, between Ticket.ProblemCode and Problem.Code

When I try to set UIHint("ForeignKey") on Ticket.ProblemCode and run the web page I get the error:

'ProblemCode' is not a foreign key column and cannot be used here.

Anyone know why? More importantly, how to fix it?

回答1:

See this post on the ASP.NET forums: http://forums.asp.net/t/1254559.aspx

Also, you said that you created the association in Linq to SQL. Is there an actual PK/FK constraint in the database, or is it only represented in your dbml?