1

We are using EF6.1.1 I have a database view. The view has "ID" column and is not nullable. I added that view on edmx designer. I notice the key icon infront for "ID" column in the designer. When I right click on "ID" column on the designer I also notice "Entity Key" option is selected But when T4 regenerates entities, I don't see the corresponding entity has "Key" attribute on the ID column. So I get compile time warning

Warning 4 Error 6002: The table/view 'XXXXXX' does not have a primary key defined. The key has been inferred and the definition was created as a read-only table/view.

LP13
  • 30,567
  • 53
  • 217
  • 400

1 Answers1

0

In your SqlServer:

CREATE FUNCTION FunctionName() RETURNS TABLE AS RETURN (SELECT * FROM [dbo].[Viewname])

In your app, upgrade your model from database and import function FunctionName.

In your controller:

var some = db.**FunctionName()**.SingleOrDefault(c => c.field == someparam);
Brian
  • 14,610
  • 7
  • 35
  • 43
George Poliovei
  • 1,009
  • 10
  • 12