Update, Insert in the Entity Framework Using View?

0

I'm having an error in my project when trying to give a Update or an Insert via Entity Framework, where I mapped a view of data.

  • defined.

    I also saw that I could change that, but I could not find where. Does anyone know how to fix this error? Where can I configure .edmx to accept Updates even do not try a primary key defined?

    Or should I map a table myself?

        
  • asked by anonymous 10.04.2016 / 08:10

    1 answer

    0
      

    I have an error in my project when trying to give an Update or an Insert via Entity Framework, where I mapped a database view.

    According to the official SQL Server documentation ( see Updatable Views ):

      

    You can modify the data in an underlying base table through a view, as long as the following conditions are true:

         
    • All modifications, including UPDATE, INSERT, and DELETE statements, should reference only one base table columns.

    •   
    • The columns to be modified in the view should reference the underlying data of the table columns directly. Columns can not be derived in any other way, such as the following:

           
      • An aggregate function: AVG, COUNT, SUM, MIN, MAX, GROUPING, STDEV, STDEVP, VAR and VARP.

      •   
      • A computation. The column can not be computed from an expression that uses other columns. Columns formed using the UNION, UNION ALL, CROSSJOIN, EXCEPT, and INTERSECT set operators result in computation and are also not updatable.

      •   
    •   
    • Modified columns are not affected by GROUP BY, HAVING or DISTINCT clauses.

    •   
    • TOP is not used anywhere in the select_statement of the view along with the WITH CHECK OPTION clause.

    •   

    If your view does not follow these conditions, it will not work. And this does not depend on the Entity Framework.

      

  • defined. I also saw that I could change that, but I could not find where. Does anyone know how to fix this error? Where can I configure .edmx to accept Updates even do not try a primary key defined?

  • This is not an error. It is an essential condition for the framework to work. The mistake is all yours.

    In order to work, you need to define at least one field as primary key . It could be more than one, by the way.

    The EDMX modeler is not the most appropriate tool for this. You will have to decorate your Model generated by EDMX with primary key attributes. See an example here .

        
    10.04.2016 / 08:35