entity-framework-4.3

Entity Framework 4.3 Code First Cannot Create Datetime2?

蓝咒 提交于 2019-12-05 05:41:12
I have my database model configured to use the datetime2 format instead of just datetime. When the database is generated all date columns are datetime and not datetime2. Here is my column configuration code; Property(a => a.LastOpened) .HasColumnOrder(++index) .HasColumnType("datetime2") .HasPrecision(0) .IsRequired(); I can swear that this worked in the earlier version of EF such as 4.1 but I don't understand why it isn't working now. I am connecting to SQL Server 2008 R2... Any help would be appreciated! Thank You! From the ADO.NET team blog : Known Issues [...] Not all hard coded column

Entity Framework 4.3.1 failing to create (/open) a database [Threading Anomaly?]

扶醉桌前 提交于 2019-12-05 05:12:57
I've used EF 4.1 ( Code First ) in an MVC 3 project a while back, and it was good. Today I tried using EF 4.3.1 ( Code First ) in a WinForms project and encountered some real voodoo: (The original project I was working on was WinForms, however the same thing is true for the attached Console Application code.) When trying to enter a simple class into the database, I get the following exception: Cannot open database "Test" requested by the login. The login failed. Login failed for user '[ComputerName]\[Administrator]'. I've tried checking the SQL Server (2008 R2) configurations but my user does

DbUpdateException with entities that do not expose foreign key properties

半世苍凉 提交于 2019-12-05 04:02:32
I have an entity model with User and Person entities, such that each User must be associated with exactly 1 Person , and each Person can be associated zero or 1 User . User (0..1) <-------> (1) Person The association is mapped fluently. Originally I only had it declared on the Person side: private class PersonOrm : EntityTypeConfiguration<Person> { internal PersonOrm() { ToTable(typeof(Person).Name, DbSchemaName.People); // has zero or one User HasOptional(p => p.User) .WithRequired(d => d.Person) .Map(d => d.MapKey("PersonId")) .WillCascadeOnDelete(false) ; Since I encountered this error, I

EF4.3.1 on .NET 4 - The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type

二次信任 提交于 2019-12-05 00:06:40
Update: Subject updated - this is now reproducible on EF 4.3.1 under .NET 4 running with VS2012 installed under Windows 8. Any ideas why this would start happening now? The subject says it all really. We just upgraded from EF 4.3 code-first to EF 5 running under .NET 4.0. We have a query that looks similar to the following: ctx.Set<Entities.A>().Select(a => new DTO.A { Id = a.Id, Name = a.Name }).ToArray(); Entities.A is defined in an assembly called Entities and DTO.A is defined in an assembly called DTO . In EF 4.3 this worked fine, but under EF 5.0 it throws the following exception: Schema

Entity Framework Code First : How to map flat table to class with nested objects

时光毁灭记忆、已成空白 提交于 2019-12-04 19:00:41
问题 I have the scenario where the data from a single table must be in 2 objects. [Table] -Field1 -Field2 -Field3 -Field4 And the class look like this: [Class1] -Field1 -Field2 -Class2 object here [Class2] -Field3 -Field4 I have set in the Class1 the attribute [NotMapped] over the property of the Class2 which contain the field 3 and 4. I also have added the configuration in the Database Context: public class ConfigurationClass1 : EntityTypeConfiguration<Class1> { public ConfigurationClass1 () {

How do OnModelCreating and non automatic Migrations relate?

孤人 提交于 2019-12-04 11:20:17
问题 When I add a new table that has some relations to my database and then run Add-Migration I see that code is generated in the Up method to add the table and its relations. However, I prefer to define the relation using the fluent API in the OnModelCreating method. How do these two methods interact? Can I delete the code from the Up method that defines the relation for instance? 回答1: Each of them has completely different purpose: OnModelCreating is used for inline fluent-API definitions of your

Make EF4.3 Code First Migrations ignore pending migrations

北战南征 提交于 2019-12-04 07:18:00
I have a local instance of a database that I recently created using DbContext.Database.Create() , so the __MigrationHistory table exists with an InitalCreate entry that matches the code at the moment. Some code-based migrations exist in the Migrations folder, however. These will be run in our development and staging environments to bring those databases in line with the code. I don't need to apply them locally, however, since I created the database using the current code. I now need to make a change to the model and create the corresponding migration. But when I run Add-Migration TestMigration

Why are my EF Code First pregenerated views having no effect?

泄露秘密 提交于 2019-12-04 03:59:51
I have ~300 DbSets in my context and the first query after app load (a FirstOrDefault() where on an indexed field) takes ~40 seconds. To improve this, I am attempting to use pregenerated views in EF 4.3.1 Code First using the T4 template here: http://blog.3d-logic.com/2012/06/13/entity-framework-codefirst-view-generation-templates-on-visual-studio-code-gallery/ I compile it in, but I see no performance difference. I was hoping/assuming it would help the painful slow startup I am experiencing, but no luck. Should it help? If not, what exactly are pregenerated views used for? And, is there

EF 4.3 Migration - how to produce a downgrade script?

六月ゝ 毕业季﹏ 提交于 2019-12-04 01:37:07
I have an issue which I could not find answer for across the web. I am using CodeFirst EF 4.3.1 Migrations with MsSQL. I have added several migrations and now I want to produce a script for upgrade/downgrade between two migrations. For upgrade I run the following command which successfully reproduces an upgrade script: PM> Update-Database -Script -SourceMigration:"201205161144187_AddPostAbstract" -TargetMigration:"201205161203310_BlogLimitsAndTableRename" However, for downgrade I run the following command which fails with the following error: PM> Update-Database -Script -SourceMigration:

Entity Framework CodeFirst KeyNotFoundException in MemberDomainMap

时间秒杀一切 提交于 2019-12-03 21:58:39
问题 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