views:

28

answers:

1

One of my Entity Framework Models contains a MS-SQL View. The View is called User and contains various properties for users.

When I right click on the model and select Update Model from Database, I get the following error: "An exception of type 'System.InvalidOperationException' occurred while attempting to update from the database. The exception message is: 'A model generation extension made changes to the model generated from the database that were not valid'.

This occurs in any model we have that uses a View in Entity Framework 4.0. It's getting very tedious to delete and recreate the model every time some part of the database structure changes. Is there anyway to make "Update Model from Database" work when my model contains a View?

If it makes a difference, this is a readonly View.

EDIT: I forgot to mention, this is a cross-database View. That seems to be where the problem occurs. A regular view (within the same database) works fine.

Here's a my sample EDMX file. I'm not sure if it will be useful or not.

<edmx:Edmx Version="2.0" xmlns:edmx="http://schemas.microsoft.com/ado/2008/10/edmx"&gt;
<edmx:Runtime>
<edmx:StorageModels>
  <Schema Namespace="SignupsModel.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2008" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl"&gt;
    <EntityContainer Name="SignupsModelStoreContainer">
      <EntitySet Name="Users" EntityType="SignupsModel.Store.Users" store:Type="Views" Schema="dbo">

      </EntitySet>
    </EntityContainer>
        <EntityType Name="Users">
      <Key>
        <PropertyRef Name="userID" />
      </Key>
      <Property Name="userID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
      <Property Name="userName" Type="varchar" Nullable="false" MaxLength="50" />
      <Property Name="campusID" Type="varchar" Nullable="false" MaxLength="7" />
      <Property Name="firstName" Type="varchar" Nullable="false" MaxLength="30" />
      <Property Name="middleInitial" Type="varchar" Nullable="false" MaxLength="1" />
      <Property Name="lastName" Type="varchar" Nullable="false" MaxLength="30" />
    </EntityType>
  </Schema>
</edmx:StorageModels>
<edmx:ConceptualModels>
  <Schema Namespace="SignupsModel" Alias="Self" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns="http://schemas.microsoft.com/ado/2008/09/edm"&gt;
    <EntityContainer Name="Entities" annotation:LazyLoadingEnabled="true">
      <EntitySet Name="Users" EntityType="SignupsModel.User" />
    </EntityContainer>
    <EntityType Name="User">
      <Key>
        <PropertyRef Name="userID" />
      </Key>
      <Property Name="userID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
      <Property Name="userName" Type="String" Nullable="false" MaxLength="50" Unicode="false" FixedLength="false" />
      <Property Name="campusID" Type="String" Nullable="false" MaxLength="7" Unicode="false" FixedLength="false" />
      <Property Name="firstName" Type="String" Nullable="false" MaxLength="30" Unicode="false" FixedLength="false" />
      <Property Name="middleInitial" Type="String" Nullable="false" MaxLength="1" Unicode="false" FixedLength="false" />
      <Property Name="lastName" Type="String" Nullable="false" MaxLength="30" Unicode="false" FixedLength="false" />
    </EntityType>
  </Schema>
</edmx:ConceptualModels>
<edmx:Mappings>
  <Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2008/09/mapping/cs"&gt;
    <EntityContainerMapping StorageEntityContainer="SignupsModelStoreContainer" CdmEntityContainer="Entities">
      <EntitySetMapping Name="Users"><EntityTypeMapping TypeName="SignupsModel.User"><MappingFragment StoreEntitySet="Users">
        <ScalarProperty Name="userID" ColumnName="userID" />
        <ScalarProperty Name="userName" ColumnName="userName" />
        <ScalarProperty Name="campusID" ColumnName="campusID" />
        <ScalarProperty Name="firstName" ColumnName="firstName" />
        <ScalarProperty Name="middleInitial" ColumnName="middleInitial" />
        <ScalarProperty Name="lastName" ColumnName="lastName" />
      </MappingFragment></EntityTypeMapping></EntitySetMapping>
    </EntityContainerMapping>
  </Mapping>
</edmx:Mappings>

+1  A: 

I think I tracked down the issue. A while back, I guess I installed a Visual Studio addon called "Edmx Views Processor". I thought I had uninstalled it. Removing the addon seems to solve the issue.

The extension in question is located here: http://visualstudiogallery.msdn.microsoft.com/en-us/d9b76b5d-d45c-4e79-8d28-31444be582de

Jared S