How do you add a primary key to a sql view? - Or alternate way to link views to LINQ-2-Entities

后端 未结 2 876
我寻月下人不归
我寻月下人不归 2021-02-05 23:54

I\'m adding a very simple view (or trying to) to my entities object model. The database is in SQL Server 2008. I\'m on .Net 3.5 (SP1) using C#.

The view has two fields

相关标签:
2条回答
  • 2021-02-06 00:24

    I dont know if this will help you, but you can create a primary key using a multi-statement table-valued function.

    I cant find any ref to a primary key for a view, but i know it can be done with a table function.

    CREATE FUNCTION (Transact-SQL)

    0 讨论(0)
  • 2021-02-06 00:34

    After you create the view using schemabinding you can add a primary key to it:

    CREATE VIEW Colors WITH SCHEMABINDING
    AS SELECT Color='yellow', ColorCount=100
    GO
    CREATE UNIQUE CLUSTERED INDEX PK_Colors ON Colors (Color)
    
    0 讨论(0)
提交回复
热议问题