ADO .NET函数导入. [英] ADO .NET Function import.

查看:89
本文介绍了ADO .NET函数导入.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我已经实现了Windows客户端程序,以使用ado.net实体框架访问数据库.在数据库中,我还具有视图"和存储过程".我在ado.net中使用函数导入来调用存储过程.通过视图"搜索存储过程.

我现在遇到的麻烦就是这样.说,我通过连接两个表"Persons"和"PersonalIdentities"创建了一个视图,每个人不能有一个或多个身份.因此,当我离开外部联接表"Persons"时
如果一个人有很多身份数据库视图,则使用"PersonalIdentities"显示该人的多个记录.

前一个人的名字是Isuru,具有两个标识542698V,458216X

数据库视图是这样的

|伊苏鲁| | 542698V |
|伊苏鲁| | 458216X |

我创建的存储过程可以搜索人名,并从视图中给出结果集.如果我执行存储过程,它将按预期方式工作.但是,当我在实体框架工作中使用函数导入调用存储过程时,会发生这种情况.

|伊苏鲁| | 542698V |
|伊苏鲁| | 542698V |

它给出两个记录,但记录相同.我花了几个小时,无法提出解决方案.

我的公开时间太长,无法解释这种更好的方法.感谢和问候.

Hi Everyone,

I have implemented a windows client program to access a database using ado.net entity framework. In database I also have "views" and " stored procedures" . I use function imports in ado.net to call stored procedures. Stored procedure search through the "view".

Trouble I''m having now is like this. Say ,I created a view by joining two tables "Persons" and "PersonalIdentities" each person can have no or more than one identities. So when i left outer join table "Persons"
with "PersonalIdentities" if one person have many identites database view show multiple records for that person Person.

Ex person name is Isuru and have two identites 542698V, 458216X

Database view is like this

|Isuru| |542698V|
|Isuru| |458216X|

Stored procedure I created can search for person name and give results set from view. If I execute stored procudre, It works the expected way. But when I call stored procedure using function import in entity frame work, this happens.

|Isuru| |542698V|
|Isuru| |542698V|

It gives two records but same record. I dig hours and couldn''t came up with a solution.

My discripion is too long, I couldn''t explain this better way. Thanks and regards.

推荐答案

为实体框架模型拉入视图时,在创建视图的存储模型时,它会自动推断出该存储模型实体的密钥.存储模型实体的关键字应能够唯一地标识基础视图中的行.如果推断不正确,可能会导致意外情况,例如您的情况.

因此,作为第一步,您可以检查是否已在视图的存储模型实体中推断出正确的键(推断的键应能够唯一地标识视图中的行).您可以通过右键单击设计器中视图的概念模型实体并选择表映射"来执行此操作.在左侧的映射详细信息窗格中,您将能够看到视图的存储模型实体的列和键.如果推断出不正确的键,则可以尝试向视图中添加更多列(尤其是源表的主键),并查看实体框架是否正确地推断了键.

不幸的是,如果密钥推断不正确,则当前版本的实体框架将不允许您通过设计器更改存储模型实体的密钥.您只能更改概念模型实体的键.尽管您可以通过编辑.edmx文件来更改存储模型密钥,但是每次模型与数据库同步时,所做的更改都会丢失.

您可以从以下链接中获取更多信息和一些解决方法,

http://social.msdn.microsoft.com/论坛/en-US/adodotnetentityframework/thread/ea0bf748-bc97-439d-99b0-76180b2161bb [ http://asheeshsoni.blogspot.com/2009/09/entity- framework-messes-up-primary-keys.html [ ^ ]

希望此信息对您有所帮助.祝你好运!
When you are pulling in a view for an entity framework model, at the time the storage model for the view is created, it automatically infers the keys for that storage model entity. Keys of a storage model entity should be able to uniquely identify a row in the underlying view. If inferred incorrectly it could result in unexpected behavior such as in your case.

Therefore as the first step you can check whether the correct keys has been inferred in the storage model entity for your view (Inferred keys should be able to uniquely identify a row in the view). You can do this by right clicking on the conceptual model entity for the view in the designer and selecting "Table Mapping". In the mapping details pane on the left side, you will be able to see the columns and the keys of the storage model entity of your view. If the incorrect keys have been inferred you can try adding more columns to the view (especially the primary keys of the source tables) and see whether the entity framework infers the keys correctly.

Unfortunately if the keys are inferred incorrectly, the current version of entity framework won’t let you change keys of the storage model entities through the designer. You can only change the keys of the conceptual model entities. Though you can change the storage model keys by editing .edmx file, the changes will be lost each time the model synced with the database.

You can get more info and some workarounds from the following links,

http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/ea0bf748-bc97-439d-99b0-76180b2161bb[^]

http://asheeshsoni.blogspot.com/2009/09/entity-framework-messes-up-primary-keys.html[^]

Hope this information was helpful. Good luck!


这篇关于ADO .NET函数导入.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆