【问题标题】:How to create PRIMARY KEY in VIEW that uses OUTER JOIN如何在使用 OUTER JOIN 的 VIEW 中创建 PRIMARY KEY
【发布时间】:2016-10-11 15:06:49
【问题描述】:

我创建了必须使用FULL OUTER JOIN 的视图。

我想通过 DbFirst 方法在 EDMX 中使用此视图。

EDMX 正在生成下一个警告:

<!--Errors Found During Generation: warning 6013: The table/view 'MyView' does not have a primary key defined and no valid primary key could be inferred. This table/view has been excluded. To use the entity, you will need to review your schema, add the correct keys, and uncomment it.

我试图通过添加来解决这个问题 CREATE UNIQUE CLUSTERED INDEX PK_MyView ON [dbo].[MyView] (Id) 但是 Sql 说: Cannot create index on view "dbo.MyView" because it uses a LEFT, RIGHT, or FULL OUTER join, and no OUTER joins are allowed in indexed views. Consider using an INNER join instead.

有没有办法将不带PK的视图添加到edmx或将PK添加到视图。

【问题讨论】:

    标签: sql-server entity-framework ef-database-first sql-view


    【解决方案1】:

    您正在创建索引视图,并且您可以在索引视图中执行的连接类型受到限制。主要是,您只能执行内部联接。不允许所有其他类型的连接。

    有一个解决此限制的方法,您可以阅读here 以查看它是否适合您的情况。不过,这并不是一个特别有吸引力的解决方法。

    您通常不需要索引视图,除非您打算使用索引视图来聚合数据,这是索引视图的主要用途。否则,在基表上具有适当的索引应该消除对索引视图的需要。

    【讨论】:

    • 我需要索引视图,因为实体框架需要它。索引是指索引作为主键。
    猜你喜欢
    • 2020-02-26
    • 2012-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-10
    • 1970-01-01
    • 2012-06-25
    相关资源
    最近更新 更多