how to modify error when row not found in zend doctrine - zend-framework

So I have this exact error and it happens when there is an association and that row isn't found with the matching ID.
related question
I have searched through but couldn't find any such solution to the problem. Is there any way to tell doctrine to ignore if row not found? Or if modifying error.
I could query to check but that isn't appropriate since we call via $entity->getOtherEntity()

Related

Entity framework error on updating model from database and vice versa

Here is what happens when I try to update model from database with VS express 2013 for the web, EF6.1.1 and .NET framework 4.5.
In this case I just added a field to a table in the table definition and updated the database.
After that I right click update model from database in the EDMX model view and I get this error message:
An exception of type ‘System.runtime.interopServices.COMException’
occurred while attempting to update from the database. The exception
message is: ‘A file or folder with the name ‘Model.Context.tt’ already
exists. Please give a unique name to the item you are adding or delete
the existing item first.
I noticed that I get the same error message when I try to generate the database from the model.
I tried the following methods:
How do you update an edmx file with database changes?
http://blog.jongallant.com/2012/08/entity-framework-manual-update.html#.VMYYRv7A7mH
but none of them worked.
I also found that https://entityframework.codeplex.com/workitem/1104 and it seems that it has been resolved with “commit 7e8331d1d22d (EFTools repo)”.
Anyone can help me on how to solve my problem or on what is “commit 7e8331d1d22d (EFTools repo)” ?
Thanks
Boid’
It's an old question but I just run into the same issue. Finally found a solution in this bug report. Check if you have any *.tt files that are not added to solution and remove them. That fixed the problem for me.

EF5 keeps referencing property that no longer exist

I have an EF5 Model, I renamed a couple of tables and fields because they were spelled wrong. Now when I re update the model from the DB it makes all the correct associations and entities and context all change. But I keep getting this error below. Mind you the field "BrowserDetailId" no longer on any table nor in Fk relationship. I get this error only at run time, and I cant find where it thinks the FK relationship still exists.
Schema specified is not valid. Errors: The relationship 'PortalModel.FK_LoginActivity_LoginAttempts' was not loaded because the type
'PortalModel.LoginAttempt' is not available. The following information may be useful in resolving the previous error:
The required property 'BrowserDetailId' does not exist on the type 'Portal.Entities.LoginAttempt'.
The relationship 'PortalModel.FK_VerificationAttempts_Verification' was not loaded because the type 'PortalModel.Verification' is not available.
The following information may be useful in resolving the previous error:
The required property 'BroswerDetailId' does not exist on the type 'Portal.Entities.Verification'.
I have deleted edmx and related context and entities and recreated them, still get the error.
I have delete the FK's to the related to tables and updated the edmx model and still get the error.
I have created new edmx file and context and entites still get the error.
I have searched all the files in the solution and cant find any mention of the "BrowserDetailId".
I have been trying to figure this out for more time then i would like to admit, any help would be great.
The database is SQL Server 2008

Looping gets "EntityReference can have no more than one related object" error

I am receiving this error: "A relationship multiplicity constraint violation occurred: An EntityReference can have no more than one related object, but the query returned more than one related object. This is a non-recoverable error."
It happens during a loop through a set of objects, in this case when it gets to the second one in the loop. The error seems to indicate that one of the reference properties of the object in the list I am looping through is throwing this error. I know that the data is correct on the database side, so I'm not sure what Entity Framework is seeing here that it doesn't like.
This is the fluent configuration in question:
modelBuilder.Entity<TemplateSubscriber>()
.HasRequired(r => r.Role)
.WithOptional()
.Map(m => m.MapKey("RoleID"))
.WillCascadeOnDelete(false);
This particular configuration allowed me to get the correct SQL generated in my DbMigration, and I am happy with the database, however something must be wrong with how EF sees this relationship, because it throws this error when it tries to load up a second "TemplateSubscriber" in a loop, and that error is seen specifically on trying to load the "Role" reference property.
The relationship is a one to many, with the relationship accessible only from the one side. I have no need to access a list of the templateSubscribers from within the role. So what I wanted was a foreign key relationship so that the templateSubscriber must reference an actual role.
What could be the issue here? And how can I see what the SQL statement is that is erroring out, I would probably be able to diagnose if I could see the SQL.
This was the answer:
https://stackoverflow.com/a/9269397/1296464
Needed to change WithOptional() to WithMany()
It didn't make a change in the DB, but something under the hood is better now.
I had a similar issue. Mine was a result of using LazyLoading and not having all my navigation properties set to Overridable (c# virtual). This error occurred when having one end of the navigation set as Overridable and the other not.

EF return parent entity only

I'm having an issue when trying to serialise an entity. An error is being through saying that the query may result in a circular query. Ideally I just want to pull out the entity with no relationships attached. I've seen some examples where you can set the relation accessor to Internal but this causes other issues. Is there a way to do this in straight LINQ?
Thanks for the help.
Try returning a single entity using FirstOrDefault()
The reason that you are getting the circular error is probably due to your data model where a row points to the parent which could be the same row.

Entity Framework 4.0: Adding scaler property gives error (property it not mapped: 11009)?

I wanted to add a new property to one of my model (table). Basically its a property that doesn't exist in the database but i need to add it to my model so that the custom generation tool (self tracking entity generator) will create the the property inside the the custom generated file.
I added a scaler property, its a string and called testme but it gives me the following error, Anybody know how i can fix this?
Error 2538 Error 11009: Property 'testme' is not mapped.
I am confused why do i need to map it to a table... its a field that doesn't exist in the table ...
Any help really appreciated
Thanks
Generally, you add un-mapped properties to a partial class instead of via the model. That said, use discretion; un-mapped properties can be confusing, since they mostly can't be used in LINQ to Entities queries.
I encountered this problem and was able to resolve it by deleting the entity (a view) in tne designer and readding it by refreshing from the database. This occured after a major redesign of the database and rewriting the view.
I know this doesn't address your problem, but Googling for this error returns this question. Hopefully this answer will be useful to others who are new to EF and hit this message, like I did.
I've been generating my DB from my conceptual model. If I modify the model without updating the DB, then I see this error message.
At the moment I don't have any data in my model, so simply regenerating the DB from the changed model makes these errors go away.