none
Problem in Mapping Fragment

    Question

  • Hey Folks,

    I have question about the ADO.NET Entity Framework and I hope somebody here can help.

    I have an MS SQL database and am building an application that uses it.  I'm using the EF to access my database.  I'm constantly modifying my database and then updating my edmx file as I develop this.

    I've encountered a recurring problem where I have a view that the "Update Model from Database" process overwrites my manual changes and messes up my app.  It is a simple fix, but it bothers me to have to change every time I do an update.

    The problem is with what the "update" process does in terms of choosing a primary key for my view. 

    The following is what is automatically generated:

    Code Snippet

    <!--Errors Found During Generation:
          warning 6002: The table/view 'C:\PROJECTS\DEMM\DEMMDATASERVICES\DEMM.MDF.dbo.vwDocumentTypeCounts' does not have a primary key defined. The key has been inferred and the definition was created as a read-only table/view.
          -->
            <EntityType Name="vwDocumentTypeCounts">
              <Key>
                <PropertyRef Name="ProjectID" />
              </Key>
              <Property Name="ProjectID" Type="int" Nullable="false" />
              <Property Name="DocumentType" Type="int" />
              <Property Name="DocCount" Type="int" />
        </EntityType>
     


        

    And this is what I have to manually change everytime I do an "Update":
     

       

    Code Snippet

              

      <!--Errors Found During Generation:
          warning 6002: The table/view 'C:\PROJECTS\DEMM\DEMMDATASERVICES\DEMM.MDF.dbo.vwDocumentTypeCounts' does not have a primary key defined. The key has been inferred and the definition was created as a read-only table/view.
          -->
            <EntityType Name="vwDocumentTypeCounts">
              <Key>
                <PropertyRef Name="ProjectID" />
                <PropertyRef Name="DocumentType" />

              </Key>
              <Property Name="ProjectID" Type="int" Nullable="false" />
              <Property Name="DocumentType" Type="int" Nullable="false" />
              <Property Name="DocCount" Type="int" />
            </EntityType>


    Is there a setting I can add that will tell the "Update" process to ignore this view, and not undo my changes?

    Thanks,
    James
    Friday, December 05, 2008 8:28 PM

All replies

  • The update process regenerates your SSDL and so overwrites any changes to it. We are aware of, and would like to fix, this problem but do not yet know when we will be able to do it.

    Friday, December 05, 2008 9:45 PM
  • Can I add another request for a solution to this problem. We have a few views which the update tool generates unnecessary keys for which we have to go and remove every time the model is updated for any reason, and it is causing angst. MSDN says
    "Changes made to the SSDL section of an .edmx file, as suggested in the procedures below, will be overwritten if you use the Update Model Wizard to update your model. To avoid manually editing the .edmx file in this case, modify your database schema so that each table has a primary key or so that one or more columns of each table or view is non-nullable or non-binary."
    which is not useful. It is not possible to set every column we include in a view nullable. Is there any way to:
    • automatically remove unnecessary keys after an update, or
    • have the update tool not mess with a view key once it has been generated, or
    • have the tool infer a minimal key (first non nullable, non binary column, instead of ALL non nullable non binary columns)?
    Monday, March 02, 2009 6:34 AM
  • Are you still "aware" of this problem?

    Dave

    Sunday, August 25, 2013 4:28 PM