Entity framework result discrepancy for a database views

后端 未结 2 1561
抹茶落季
抹茶落季 2020-12-10 12:06

I have one specific view created in my DB(joins about 5-6 tables with a left join).This view is added to my edmx (entity framework 1.0) . Recently I noticed that one of the

相关标签:
2条回答
  • 2020-12-10 12:56

    The problem is in fact with the key. You have to a) have a unique identifier for each row in the view. and b) map that key accordingly in the edmx. Otherwise as your quote states, the mapping logic will see each subsequent row and figure that it can use the same object instance that it returned before

    0 讨论(0)
  • 2020-12-10 13:12

    Same problem for me. An Entity View (VReport) was generated automatically from VS2010 wizard to something like:

    class VReport
    Line: int (key) 
    Desc: string 
    Date: DateTime
    

    When I retrieved the records from the database, the SQL query was formed correctly and returned the expected (and distinct) results, but the Entity Framework instead returned a lot of duplicated records.

    But instead, also the Date column/field would have to partecipate in the formation the Entity KEY

    So, to resolve this issue, I changed the property of the field from Entity Key: false -> true

    class VReport
    Line: int (key) 
    Desc: string 
    Date: DateTime (key)
    
    0 讨论(0)
提交回复
热议问题