EF4 视图被排除。当我无法控制数据库时如何包含它?
我正在通过 EF4 使用 MSSQL 数据库,并且需要包含(员工)视图。它有一个employeeid 列,但该列似乎允许空值(172,000 行中只有1 行,我猜测是应用程序使用的某种占位符或默认值)。如果我在构建模型时选择视图,则会收到此错误:
“表/视图 TABLE_NAME 没有定义主键,无法推断出有效的主键。此表/视图已被排除。要使用该实体,您需要检查您的架构,添加正确的键,然后取消注释”。
我无法控制数据库,我无法查看视图的定义来确定基础表,数据库的设计不会改变,但我需要包含此视图中的用户数据。
有没有办法强制模型包含它?
谢谢
我
I'm consuming a MSSQL DB via EF4 and need to include a view (of employees). It has an employeeid column, but this column appears to allow nulls (there's only 1 out of 172,000 rows which I am guessing is some kind of placeholder or default value used by the application). If I select the View when building the model I get this error:
"The table/view TABLE_NAME 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".
I have no control over the DB, I am unable to view the definition of the view to determine the underlying tables, the design of the DB is not going to get changed, but I need to include the user data from this view.
Is there a way I can force the model to include it?
Thanks
M
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在特定情况下使用了所谓的“物化”,
整个想法是您可以添加老式的 ADO 存储过程并使其从对象上下文中调用。
这是您不需要对 edmx 或数据库进行任何更改
post 显示了一个简单的示例
I had specific cases where I made use to what is know as "Materialization"
the whole idea is that you can add the old fashioned ADO stored procedure and makes it called from the object context.
this was you don't need to do any changed on the edmx or the database
this post shows a simple example