Distinguishing between storage model and conceptual model field names (Entity Framework) - entity-framework

Every sample I come across has the entities and properties in the storage model named exactly the same as in the conceptual model. So in the mapping section, I can't tell whether an entity or property is from the storage model or conceptual model.
This is a snippet of an Entity Framework diagram. Which "ID" fields are from the database and which are from the entities?
<AssociationSetMapping Name="FK_Orders_Customers" TypeName="ContosoModel.FK_Orders_Customers" StoreEntitySet="Order">
<EndProperty Name="Customer">
<ScalarProperty Name="ID" ColumnName="CustomerID" />
</EndProperty>
<EndProperty Name="Order">
<ScalarProperty Name="ID" ColumnName="ID" />
</EndProperty>
</AssociationSetMapping>

Well only databases have Columns, so ColumnName is the Database Name.
Name is from the Entity (or in this case the Association).
Hope this helps
Alex

Related

Is there an equivalent to updateSchema="false" that applies to individual entities?

Setting updateSchema="false" in the configuration section of the XML file for the SQL producer will prevent Codefluent from altering the schema (i.e. field names, field type, indexes, etc) of the SQL table while still allowing for the creating of stored procedures and methods against the table. This is discussed in the blog article https://blog.codefluententities.com/2011/10/31/interoperate-with-an-existing-database-using-codefluent-entities/
Question
Is there anything built in that would achieve the same effect but apply only apply to the underlying tables of specific entities?
You can disable table diffs generation for a specific entity using an attribute:
<cf:entity name="Customer" cfps:produceTableDiff="false">
<cf:property name="Id" key="true" />
</cf:entity>

How specify the identity seed for a property in the CodeFluent model?

All the key properties in my CodeFluent model are of type ulong and must be automatically incremented by the database, for example:
<cf:property name="Id" typeName="ulong" key="true" persistenceIdentity="true" cfps:hint="CLUSTERED" />
One specific key property must start with the value 10 instead of 1.
How can I specify this?
Another question: Do you have documentation about the cfps namespace?
Using the latest version of CodeFluent Entities (>=836) you can set the identity seed and increment at property level:
<cf:property name="Id" typeName="int"
cfps:identitySeed="10"
cfps:identityIncrement="2"
xmlns:cfps="http://www.softfluent.com/codefluent/producers.sqlserver/2005/1"/>

Entity Framework EDMX Diagram table missing properties after update

I'm maintaining an asp.Net MVC 3 web application using Entity Framework 4.1 Database first approach. I have had to add two new properties to one of the tables in the database.
I then right clicked on the EDMX diagram and choose 'Update Model from Database' within the context menu, like so:
This works without any problems, but the two new fields aren't added to the expected table. However, when I open the EDMX file in XML format, I can see the two new fields listed, like so:
<EntityType Name="Shift">
<Key>
<PropertyRef Name="shiftID" />
</Key>
<Property Name="shiftID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
//Two new fields below
<Property Name="shiftTitleGradeID" Type="int" />
<Property Name="shiftTitleSubID" Type="int" />
</EntityType>
Can anyone advise me on how to get the two new fields into my EDMX diagram and not just the XML file?
Thanks in advance.
Got it fixed. I had to delete all references to the new properties in the XML file. Then recreate the update model from database procedure, this time ensuring the two checkboxes where ticked, Pluralize or singularize generated object names, and, Include foreign key columns in the model (I thought I had these ticked the first time, but I didn't).
This fixed my problem.

EF5: Multiple result sets from stored procedure

I followed this article to retrieve multiple entity sets from a stored procedure.
I have altered the column mappings of my entities so they pass through Resharper.
Do I have to rewrite the column mappings in the result mapping?
For example I have the following EntitySetMapping:
<EntitySetMapping Name="IrmaObjectConfiguraties">
<EntityTypeMapping TypeName="IrmaModel.IrmaObjectConfiguratie">
<MappingFragment StoreEntitySet="IrmaObjectConfiguratie">
<ScalarProperty Name="Gid" ColumnName="GID" />
<ScalarProperty Name="IrmaObjectGid" ColumnName="IrmaObject_GID" />
<ScalarProperty Name="IrmaConfiguratieGid" ColumnName="IrmaConfiguratie_GID" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
This entity is returned bij as part of the stored proc result sets:
<ResultMapping>
<EntityTypeMapping TypeName="IrmaModel.IrmaObjectConfiguratie">
<!--ScalarProperty Name="Gid" ColumnName="Gid" />
<ScalarProperty Name="IrmaObjectGid" ColumnName="IrmaObject_Gid" />
<ScalarProperty Name="IrmaConfiguratieGid" ColumnName="IrmaConfiguratie_Gid" /-->
</EntityTypeMapping>
</ResultMapping>
When I remove the remarks the execution of the imported function goes ok, but when there is no column mapping I retrieve the following error:
The data reader is incompatible with the specified
'IrmaModel.IrmaObjectConfiguratie'. A member of the type,
'IrmaObjectGid', does not have a corresponding column in the data
reader with the same name.
As a workaround I could define all column mappings again, but is is also possible to use the column mappings that are defined in the EntitySetMapping?
I don't think ResultMapping re-uses mappings from EntitySet mappings. Seems (I am not 100% positive here) that if you don't specify property <-> column mappings EF will try to use property names as column names in the resultset returned by your stored procedure.

What am I doing wrong to get "Two Entities with different keys are mapped to the same row

See images:
EF Designer
SQL Tables
"Two entities with different keys are mapped to the same row. Ensure these two mapping fragments do not map two groups of entities with overlapping keys to the same group of rows."
In fact, only one of the two (or 6 here) entities will have the key for the single row.
How may I overcome this? SQL View that combines them all to one row? Calculated discriminator column in ContactMethod? How should I have designed the tables differently to work better with EF?
Or is there some XML editing I can do to keep my schema and just tell EF to trust me that I'd never put the same Id in more than one derrived class?
Here's: edmx if it helps.
The link to edmx file is not work. Perhaps, you have to add a condition tag
<Condition ColumnName="ContactId" IsNull="false" />
to your edmx file using xml-editor:
<AssociationSetMapping Name="FK_Contact_ContactMethod" TypeName="SomeNamespace.FK_Contact_ContactMethod" StoreEntitySet="ContactMethod">
<EndProperty Name="ContactMethod">
<ScalarProperty Name="ContactMethodId" ColumnName="ContactMethodId" />
</EndProperty>
<EndProperty Name="Contact">
<ScalarProperty Name="ContactId" ColumnName="ContactId" />
</EndProperty>
<Condition ColumnName="ContactId" IsNull="false" />
</AssociationSetMapping>
Taking off the foreign keys to ContactMethod in the database got rid of the errors, but doesn't seem right.