entity-framework-4.3

IValidatableObject is useless for EF navigation properties?

风格不统一 提交于 2019-12-01 14:08:11
IValidatableObject.Validate only gets called when the implementing entities DbEntityEntry.State differs from "Unchanged". And just changing a navigation property won't change the state and so the validation will never occur. Why Microsoft always releases half-baked beta things? I cannot even detect the navigation property change by hand: var changes = context.ChangeTracker.Entries() .Where(e => e.State != EntityState.Unchanged) .ToArray(); Returns an empty array. There are a few interesting points here. EntityFramework tracks changes to navigation properties independently on the changes to

Entity Framework CodeFirst KeyNotFoundException in MemberDomainMap

天涯浪子 提交于 2019-12-01 00:26:45
Trying to run down an error in my EF datacontext implementation that is yielding a fairly cryptic error. Test Name: Nodes_can_be_saved Test FullName: MyProj.Test.Integration.AFDataContextTest.Nodes_can_be_saved Test Source: c:\Users\pvencill. \Documents\Visual Studio 2012\Projects\MyProj\MyProj.Test\Integration\AFDataContextTest.cs : line 49 Test Outcome: Failed Test Duration: 0:00:01.4192808 Result Message: Test method MyProj.Test.Integration.AFDataContextTest.Nodes_can_be_saved threw exception: System.Data.Entity.Infrastructure.DbUpdateException: Error retrieving values from ObjectStateEntry

How to get around “Internal .NET Framework Data Provider error 1025.”?

 ̄綄美尐妖づ 提交于 2019-11-30 21:33:06
I am using the Entity Framework 4.3, POCO, database first and I am getting the following error: Internal .NET Framework Data Provider error 1025. QUESTION: I think that my query expresses my intent but I seem to be hitting this error, so I am wondering if anyone knows how I could structure my query differently to get around this error? Here is the scenario... I have a SQL server 2008 database that has 2 tables - A and B: A AId (int - not null - identity - primary key) AName (nvarchar(10) - not null) B BId (int - not null - identity - primary key) SomeName (nvarchar(10) - not null) AId (int -

Entity Framework Data Annotations equivalent of .WillCascadeOnDelete(false);

 ̄綄美尐妖づ 提交于 2019-11-30 17:40:26
I'm currently using EF Code First 4.3 with migrations enabled, but automatic migrations disabled. My question is simple, is there a data annotations equivalent of the model configuration .WillCascadeOnDelete(false) I would like to decorate my class so that the foreign key relationships do NOT trigger a cascading delete. Code sample: public class Container { public int ContainerID { get; set; } public string Name { get; set; } public virtual ICollection<Output> Outputs { get; set; } } public class Output { public int ContainerID { get; set; } public virtual Container Container { get; set; }

Many-many relationship in Entity Framework Code First and using the “virtual” keyword to access each other

二次信任 提交于 2019-11-30 17:20:18
问题 This excerpt code successfully creates a many-many relationship with an explicit Junction table that has additional data within it. PROBLEM: I want to be able to access Courses from Student and vice versa, (therefore the commented virtual property. But if I uncomment it, it causes an error (see below)) If I don't explicitly create a junction table (no additional data), the virtual keyword works though as EF creates a junction table by convention. QUESTION: How can I make Student access

Why does Entity Framework's EF Migrations Add-Migration step require a database connection string?

ぃ、小莉子 提交于 2019-11-30 11:54:03
问题 I am trying to use and understand EF Migrations (using EF 4.3.1, Code First). In order to scaffold a new change, I have to use a command like this: Add-Migration MyMigration -ConnectionString "Data Source=.;Initial Catalog=mydb;" -ConnectionProviderName "System.Data.SqlClient" -StartUpProjectName MyWebsite -ProjectName MyEF.Migrations Why does Add-Migration require connection string data? Update-Database needs one, that makes sense. But doesn't Add-Migration have everything it needs from the

How are the compressed models stored in the EF 4.3 Code First Migrations __MigrationHistory table created?

不想你离开。 提交于 2019-11-30 05:48:50
问题 I'm working with Code First Migrations (Entity Framework 4.3) and I'd like to get a compressed binary version of the current model, so that I can manually compare it to the latest model stored in the __MigrationHistory table (or to one I have stored in a text file). There is the EdmMetadata.TryGetModelHash() method, but that's marked as deprecated and I want to avoid it if possible (for future-proofing reasons). How would I do this under EF 4.3? Edit: From a bit more investigation and the

How to get around “Internal .NET Framework Data Provider error 1025.”?

删除回忆录丶 提交于 2019-11-30 05:43:27
问题 I am using the Entity Framework 4.3, POCO, database first and I am getting the following error: Internal .NET Framework Data Provider error 1025. QUESTION: I think that my query expresses my intent but I seem to be hitting this error, so I am wondering if anyone knows how I could structure my query differently to get around this error? Here is the scenario... I have a SQL server 2008 database that has 2 tables - A and B: A AId (int - not null - identity - primary key) AName (nvarchar(10) -

Oracle ODP.Net and EF CodeFirst - SaveChanges Error

强颜欢笑 提交于 2019-11-29 16:12:55
Could someone help me with this: The code: Role r = new Role { ID = 1, Name = "Members" }; ctx.Roles.Attach(r); //Saving User User u = new User { Login = login, Password = password, Status = 1 }; u.Roles.Add(r); ctx.Users.Add(u); ctx.SaveChanges(); What I'm trying to do is to save a new user with an existing role. User and Role classes have a many-to-many relationship mapped by fluent-api as follows: modelBuilder.Entity<User>() .HasMany(u => u.Roles) .WithMany(r => r.Users) .Map(x => { x.ToTable("USER_ROLE_XREF", dbsch); x.MapLeftKey("ID_USER"); x.MapRightKey("ID_ROLE"); }); But when the

How to map foreign keys between TPH TPT objects - Entity Framework Code First

白昼怎懂夜的黑 提交于 2019-11-29 15:10:54
We have the following set of objects. public class Form { public int FormId { get; set; } public DateTime DateCreatedOn { get; set; } public string Status { get; set; } } // This is using TPT inheritance from Form [Table("FormA")] public class FormA : Form { public string ExtraInfoA { get; set; } public virtual ICollection<Child> Children } // This is using TPT inheritance from Form [Table("FormB")] public class FormB : Form { public string ExtraInfoB { get; set; } public virtual ICollection<Adult> Adults } public class Person { public int PersonId { get; set; } public int FormId public