I am using .net 4 and entity framework 4.x
I have 3 tables in sql server. For instance Persons, PersonClasses and Classes
Persons has pk PersonId
Classes has pk ClassId
PersonClasses has PersonId fk and ClassId fk
After adding to my EDMX i get the following error. How to resolve?
Error 3034: Problem in mapping fragments starting at lines 691, 768:Two entities with possibly different keys are mapped to the same row. Ensure these two mapping fragments map both ends of the AssociationSet to the corresponding columns.
The only solution I found to this problem was to remove all entities from the model and update the model from database fresh. This worked for me. Potentially something not working so well in the designer after you remove a few tables and replace only those few tables. Not sure at this point.
Related
Breeze.js doesn't handle many to manys, so I need to spell out the 1 to many with xref tables. But how do I force EF to expose those xrefs when generating my EDMX from the database?
The EDM designer will include the join table as an entity in the model if it includes "payload", that is, additional columns other than the PK. This post is old, but still seems to have the best description of how to do this: http://thedatafarm.com/blog/data-access/inserting-many-to-many-relationships-in-ef-with-or-without-a-join-entity/.
This is a really weird error, I have looked online and can not see any obvious reasons why this is happening.
I am using Database First Entity Framework version 5 and have added 4 tables called:
WorkStatus
JobStatus
SubJobStatus
SubJobStageStatus
JobStatus, SubJobStatus and SubJobStageStatus each has a foreign key constraint to WorkStatus.
I have updated my edmx to include these tables but for some reason each table is missing the last s from the word Status. So the tables and their navigation properties are now called:
WorkStatu
JobStatu
SubJobStatu
SubJobStageStatu
Does anyone know why this happens?
"-Status" is being interpreted as a plural, and Entity Framework is being "helpful" by de-pluralizing.
For example, if you have a table called "Customers" EF will generate an entity called "Customer", which is in fact nicer in code:
var customer = new Customer();
It isn't working out so well in your case; your tables are already singular.
You can rename your tables to "-Statuses" or update the names in the designer or disable pluralization:
Under Tools > Options
Entity framwork made a entity for each of my tables except for one, and I'm not sure why. I select it when i generate it from the database.
Here is my entity framework diagram, and the diagram in SQL:
http://imgur.com/a/zY17T
Notice how RecipeMeal is missing from entity framework. Does anyone have an idea why this might be happening?
RecipeMeal is supposed to store if a recipe is breakfast, lunch etc. It's not a column of Recipes because a recipe could be a lunch OR dinner recipe, as an example.
I am using EF 5.0
Thanks.
Entity Framework has built-in support for many-to-many relationships.
The table is exposed through the two ICollection<T> properties in Meal and Recipe.
I also found that if your table doesn't have a primary key it will also get skipped. One of my tables was just a summary table and didn't really need a primary key and it wouldn't be included in the reverse engineer. As soon as I added a primary key it was picked up.
I have database tables that look like this:
A Task can be mapped to a Module, or not mapped at all (0...1). I'm using Entity Framework database-first, and when I generated the model from the database, the Task entity came through with Modules as a collection (0 or more). So I opened up my EDMX and changed the "Modules" navigation property on Task to 0...1.
Now, when I attempt to compile, I get this error:
Error 3003: Problem in mapping fragments starting at line 1241:Given the cardinality of Association End Member Task, it should be mapped to key columns of the table TaskModule. Either fix the mapping or change the multiplicity of this end.
I don't understand what I need to do to fix this. I've looked at the association details and can't see the issue. I know I'm probably missing something stupid, but am totally stuck. Association properties:
Visual Studio 2010 SP1, Entity Framework 4.3.1.0, SQL Server 2008 R2.
One way to do this is to redefine the primary key for the TaskModule table. Instead of the primary key being (TaskId, ModuleName) it needs to be just (TaskId). Then do an update model from database and change any of the associations manually that didn't get picked up from that update.
Well your database schema is not correct with the description you give :
the TaskModule table implicates a many-to-many relationship, not a many-to-oneOrZero.
In edmx, many-to-many relation tables are not displayed, but they still exist in database.
So you should fix your database, or be happy with the relation proposed by EF !
I'm using the TPH (Table per Hierarchy) technique to map a set of entities.
DB Schema:
UserGroupLabelSpreads table having a "UserId", "GroupId" and "LabelId" nullable fields with some additional common fields.
DAL Objects:
- UserGroupLabelSpread abstract class.
- UserSpread with a discriminator having only non-null UserId.
- GroupSpread with a discriminator having only non-null GroupId.
- LabelSpread with a discriminator having only non-null LabelId.
I've managed to get this thing to work, but when I try to connect the UserSpread entity to an existing "User" entity, I'm getting the following error:
Error 1 Error 3034: Problem in Mapping Fragments starting at lines 487, 554: 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.
I've digged around to understand that the problem is that I'm mapping the UserId column twice: once for the discriminator condition and second for the association.
Am I right with my assumption? -Can I get this thing to work?
Thanks,
Nir.
There is an updated version of EDM Generator which should be able to help you. You can use it to generate, validate and more. Sorry, got the wrong link. Here is the one to v2. I believe I've had this issue. If I am not mistaken it was due to me mapping the forreign keys wrong. I was however using beta 1 of EF4 at that time and some of the messages was wrong due to the proxies. Check your forreign keys. Blog.Id ---> Blog_id was my issue. I had Blog.Id --> Blog.Id and then BlogEntry.Id ----> Blog.Blog_Id which of course doesn't work but the designer is kind of unforgiving when it comes to mapping keys.