I am having a problem when using EF4 when I try to check if an object is already in the Entity Framework context.
I have this code below
var entityName = Entity4Test + Guid.NewGuid(); using( var ctx = new EnviroDataContext() ) { var etc = new Entity { Name = entityName }; ctx.Entity.AddObject( etc ); var q = from p in ctx.Entity where p.Name == entityName select p;
My question is, why did my search after insertion go blank?
I know that the data is saved after "SaveChanges", but what if I need to "query" the memory data of the entity.
Question extension
I have a business rule that adds 1 element A, starts the insertion of other objects B. The problem is that I have a verification rule that when inserting B, t A already exists.
Since all these actions are performed before "SaveChanges", I get an error message that EntityA does not exist.
Another case , I have a Name field unique to the table. If I try to run AddEntityName ("bla") twice and then "SaveChanges", I get an exception from DB [Unique constraints] even after passing my check for insertion, which guarantees the uniqueness of the name.
Anyone have an idea?
muek
source share