Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As Craig stated above my Key property was not unique, so I ended up changing the SQL to look at follows:</p> <pre><code>SELECT ROW_NUMBER() OVER(ORDER BY Id) AS KeyId , Id , AddressId FROM MyTable WHERE Id = @Id </code></pre> <p>Then the EDMX xml looks as follows, notice the new key is a <strong>bigint</strong> and <strong>Int64</strong>:</p> <pre><code>&lt;edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx"&gt; &lt;!-- EF Runtime content --&gt; &lt;edmx:Runtime&gt; &lt;!-- SSDL content --&gt; &lt;edmx:StorageModels&gt; &lt;Schema Namespace="MyProjectModel.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/2006/04/edm/ssdl"&gt; &lt;EntityContainer Name="MyProjectModelStoreContainer"&gt; &lt;EntitySet Name="MyEntitySet" EntityType="MyProjectModel.Store.MyEntity" /&gt; &lt;/EntityContainer&gt; &lt;Function Name="sp_getMyEntity" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo"&gt; &lt;Parameter Name="Id" Type="int" Mode="In" /&gt; &lt;/Function&gt; &lt;EntityType Name="MyEntity"&gt; &lt;Key&gt; &lt;PropertyRef Name="KeyId" /&gt; &lt;/Key&gt; &lt;Property Name="KeyId" Type="bigint" Nullable="false" /&gt; &lt;Property Name="Id" Type="int" Nullable="false" /&gt; &lt;Property Name="AddressId" Type="int" Nullable="true" /&gt; &lt;/EntityType&gt; &lt;/Schema&gt; &lt;/edmx:StorageModels&gt; &lt;!-- CSDL content --&gt; &lt;edmx:ConceptualModels&gt; &lt;Schema Namespace="MyProjectModel" Alias="Self" xmlns="http://schemas.microsoft.com/ado/2006/04/edm"&gt; &lt;EntityContainer Name="MyProjectViewEntities" &gt; &lt;EntitySet Name="MyEntitySet" EntityType="MyProjectModel.MyEntity" /&gt; &lt;FunctionImport Name="GetMyEntity" EntitySet="MyEntitySet" ReturnType="Collection(MyProjectModel.MyEntity)"&gt; &lt;Parameter Name="Id" Mode="In" Type="Int32" /&gt; &lt;/FunctionImport&gt; &lt;/EntityContainer&gt; &lt;EntityType Name="MyEntity"&gt; &lt;Key&gt; &lt;PropertyRef Name="KeyId" /&gt; &lt;/Key&gt; &lt;Property Name="KeyId" Type="Int64" Nullable="false" /&gt; &lt;Property Name="Id" Type="Int32" Nullable="false" /&gt; &lt;Property Name="AddressId" Type="Int32" Nullable="true" /&gt; &lt;/EntityType&gt; &lt;/Schema&gt; &lt;/edmx:ConceptualModels&gt; &lt;!-- C-S mapping content --&gt; &lt;edmx:Mappings&gt; &lt;Mapping Space="C-S" xmlns="urn:schemas-microsoft-com:windows:storage:mapping:CS"&gt; &lt;EntityContainerMapping StorageEntityContainer="MyProjectModelStoreContainer" CdmEntityContainer="MyProjectViewEntities" &gt; &lt;FunctionImportMapping FunctionImportName="GetMyEntity" FunctionName="MyProjectModel.Store.sp_getMyEntity" /&gt; &lt;EntitySetMapping Name="MyEntitySet"&gt; &lt;EntityTypeMapping TypeName="IsTypeOf(MyProjectModel.MyEntity)"&gt; &lt;MappingFragment StoreEntitySet="MyEntitySet"&gt; &lt;ScalarProperty Name="AddressId" ColumnName="AddressId" /&gt; &lt;ScalarProperty Name="Id" ColumnName="Id" /&gt; &lt;ScalarProperty Name="KeyId" ColumnName="KeyId" /&gt; &lt;/MappingFragment&gt; &lt;/EntityTypeMapping&gt; &lt;/EntitySetMapping&gt; &lt;/EntityContainerMapping&gt; &lt;/Mapping&gt; &lt;/edmx:Mappings&gt; &lt;/edmx:Runtime&gt; &lt;!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) --&gt; &lt;edmx:Designer xmlns="http://schemas.microsoft.com/ado/2007/06/edmx"&gt; &lt;edmx:Connection&gt; &lt;DesignerInfoPropertySet&gt; &lt;DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" /&gt; &lt;/DesignerInfoPropertySet&gt; &lt;/edmx:Connection&gt; &lt;edmx:Options&gt; &lt;DesignerInfoPropertySet&gt; &lt;DesignerProperty Name="ValidateOnBuild" Value="true" /&gt; &lt;/DesignerInfoPropertySet&gt; &lt;/edmx:Options&gt; &lt;!-- Diagram content (shape and connector positions) --&gt; &lt;edmx:Diagrams&gt; &lt;Diagram Name="MyProjectModel" ZoomLevel="100" &gt; &lt;EntityTypeShape EntityType="MyProjectModel.MyEntity" Width="1.5" PointX="5.25" PointY="0.5" Height="7.8375048828125" /&gt; &lt;EntityTypeShape EntityType="MyProjectModel.MyEntity" Width="1.5" PointX="5.5" PointY="1.375" Height="1.2636116536458335" /&gt;&lt;/Diagram&gt;&lt;/edmx:Diagrams&gt; &lt;/edmx:Designer&gt; &lt;/edmx:Edmx&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload