When creating an entity using the Xrm Tooling NuGet package, I receive the following error:
Duplicate Record Found for Entity: [some entity type code] with ID: [some guid]
I am copying a bunch of attributes from another record in the same table (custom entity for which I'm splitting some records out into multiple records as part of a cleanup effort), including the primary field. However, there are no alternate keys defined for this particular entity and no duplicate detection rules enabled either.
Any idea why I'd be receiving this error?
For me personally, this was because I forgot to filter out the primary key attribute from the collection of attributes I was copying to the cloned entity.
Note that typically a better approach would be to setup a reflexive relationship, map attributes through native field mappings, and then use the InitializeFromRequest but this was a quick migration script.
One other thing that could potentially cause this error we've found: if you don't include "RequireNewInstance=true" in your connection string, you may accidentally end up with a cached connection to another org and therefore encounter duplicates if you're performing the same updates against multiple orgs.
Related
I am working on a project where I may not alter the database in any way (unfortunately). I have started the project using Entity Framework and this has worked for the first few objects that I need. Now I have come across two scenarios that I am not sure how to accommodate.
Tables without a primary key defined.
Tables using the suffix of the table name as a field.
For the first, I get an error about reviewing my schema and uncommenting the proper area of the edmx file. The table has a field that acts as primary key but is not designated as not null and does not have a primary key created for it.
For the second, there are several tables with names like order1, order2, order3 etc where the table that needs to be accessed would be a parameter of my access methods.
My thought is that it would be simplest to just manually write the SQL and bind the data to models. If I go that route would I even use EF or do I just create a new database connection? what would be the 'proper' way to go about that?
Using Telerik OpenAccess ORM I have 2 objects User and Investment. More specifically Investments contains a foreign key to User as any typical one to many relationship. In other words each User can have mutliple Investments but each Investment can only have one user.
I have then attempted to utilize the open access feature 'Is Managed'
Which should mean that I can do something like User.Investments.Clear(); and it deletes all the related investments (or at least this works fine in many-to-many relationships) but unfortunately when I attempt this I am greeted with the following error.
"Update failed: Telerik.OpenAccess.RT.sql.SQLException: Cannot insert
the value NULL into column 'UserID', table
'CODECorp.dbo.Investment'; column does not allow nulls. UPDATE
fails."
Clearly what the ORM is trying to do is remove the association (i.e. foreign key) from the investment object to the user rather than deleting it. I have confirmed this by running SQL profiler and can see that it's running an Update rather than a Delete.
So what am I missing here? Why is it incorrectly trying to remove the association rather than simply deleting the row as you would expect?
By design, the behaviour of the navigation properties with IsManaged set to True, in scenarios where a child object is deleted from the collection of the parent object, is to remove the relationship between the two objects. In other words, Telerik Data Access (previously known as Telerik OpenAccess ORM) will keep the child record in the database but will generate a statement that attempts to set the foreign key to NULL.
A solution in this situation would be to pass the collection to the Delete method of the context. For example:
dbContext.Delete(User.Investments);
dbContext.SaveChanges();
This will produce the necessary DELETE statement. More details about the management of navigation properties with Telerik Data Access is available in this documentation article.
I hope you find this feasible. I am looking forward to your feedback.
I am working on a custom ado.net provider and using that provider I am integrating Entity Framework support in Visual Studio 2010. I'm creating all possible mapping and reading all the related metadata from database for table objects. For my test, a table contains primary keys and and other fields. When I create a model from database using this table and I get a model with all column mappings and everything but I also get error messages that follow:
The model was generated with warnings or errors.
Please see the Error List for more details. These issues must be fixed before running your application.
Loading metadata from the database took 00:00:11.4799371.
Generating the model took 00:00:04.2751189.
Added the connection string to the App.Config file.
Writing the .edmx file took 00:00:00.0005060.
If I open the .edmx file with XML editor, I see the following error:
<!--Errors Found During Generation:
warning 6002: The table/view 'sqlfire.APP.CUSTOMERS' does not have a primary key defined. The key has been inferred and the definition was created as a read-only table/view.
-->
It also added a DefiningQuery with a SELECT ... statement for the table.
I am going in a circle to find a solution and desperately looking for some help on this issue.
From the error message looks like one of your table/view doesn't have a Primary-Key. EF needs a Primary-Key in every table in order to generate Entity keys.
You may still be able to run your application, but I strongly suggest you add primary keys as warned.
I'm experiencing an unusual issue with Entity Framework in VS2008. The problem is when I create my Entity Model from my existing database, the designer add all the corresponding tables but it appears that it randomly omits some of my Foreign Key fields. Yet if I browse the Model in the Browser I can clearly see that the fields were included.
This became apparent when during the build I started receiving multiple errors that these fields were not mapped. This led me to manually add the fields in the designer to the corresponding tables and map them to the datasource.
After this however, I get multiple errors:
Error 102 Error 10023: Could not find the conceptual model to validate.
Error 103 Error 10024: Could not find the storage model to validate.
Error 104 Error 10025: Could not find the mapping model to validate.
Error 105 Could not find the Conceptual Schema node to embed as a resource for input file
Error 106 Could not find the Storage Schema node to embed as a resource for input file
Error 107 Could not find the Mapping node to embed as a resource for input file
When I open the edmx file in XML Editor, the file is riddled with squiggly lines.
I have successfully created the Entity Model in VS2010 without issue but our client isn't at 4.0 Framework.
I have identified others having the issue but I can't find any resources to assist on fixing the problem.
Any suggestions would be greatly appreciated.
This is probably EF1 did not support foreign keys. So for foreign key columns EF will create navigation properties but will not create foreign key properties on the Entities. You can find foreign properties in model browser but this is in the model representing the database and not the conceptual model. Note that navigation properties are modeled based on foreign keys in the store and you are not losing the relationship functionality even though you don't have foreign keys exposed. In other words - if you use navigation properties in queries they will be translated correctly to use foreign key values in the SQL queries. One thing where having foreign key properties in the conceptual model is very useful is when you would like to reason or modify a relationship without having to load the related entity - if you know the key value you just set the foreign key property to this value and you are done with it. This is impossible in EF1 - whenever you need to change the relationship or query against a related entity you first need to load said entity and use navigation property.
What is the meaning of this exception? Where can I find references of the cause to this kind of exception?
The changes to the database were committed successfully, but an error
occurred while
updating the object context. The ObjectContext might be in an inconsistent state.
Inner exception message: Metadata information for the relationship
'MyModel.FK_T_WORKER_VEHICLE_T_VEHICLE' could not be retrieved. If mapping attributes are used, make sure that the
EdmRelationshipAttribute for the relationship has been defined in the
assembly. When using convention-based mapping, metadata information
for relationships between detached entities cannot be determined.
Parameter name: relationshipName
I am using edmx with code generation set to Default. The pocos are in different project then the edmx file.
In my case, I got same error when I added a new entity(A) to my EDMX diagram which A has Foreign key reference to an existing entity B. Then this error came up when I tried to do CRUD for B.
I did some researches and followed a tip on MetadataException when using Entity Framework Entity Connection which advises to rename metadata in Connection String but it didn't work for me.
Steps to resolve:
The issue was in entity A not B. You need to check newly added entity A to be mapped correctly to your class A in your domain. Check property names and property types to be same (i.e. a column might need to be converted to an Enum type in your diagram to be same with your entity). Keep in mind that property names are case sensitive so if they are in upper-case in your entity it should be in upper-case in your diagram.