Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
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.
Posted
Comments
[no name] 2-Jun-10 13:50pm    
It would be helpful to show what you have tried. The proc and function won't return anything more or less than you tell it to.

1 solution

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!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900