entity-framework-4.3

Entity Framework validation failed when updating a class with virtual properties

别等时光非礼了梦想. 提交于 2019-12-12 16:04:34
问题 I'm having problems updating a property of a class when the class contains virtual properties. Here is my code public class Policy { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public long id { get; set; } [UIHint("Company"), Required] public virtual Company company { get; set; } [UIHint("Productor"), Required] public virtual Productor productor { get; set; } [MaxLength(1000)] public string comments { get; set; } } public class Company { [Key] [DatabaseGenerated

How can I generate DDL scripts from Entity Framework 4.3 Code-First Model?

戏子无情 提交于 2019-12-12 11:19:50
问题 I have a project I'm trying to deploy and I'm using a cheap host to get started. As part of the hosting package I have a SQL Server database, but I don't have drop or create privileges, I can only use the database they've created for me. Being that's the case, I want to get the DDL so I can run it manually. I'm aware I could script the database create scripts from SQL Management Studio, and that may ultimately work fine, but I'd like to automate the process as much as possible, so if I could

Entity Framework Error: Could not find the conceptual model type for X

我的梦境 提交于 2019-12-12 11:04:02
问题 I have a demo project with two folders: Data /DbContext /EntityFramework Both have an EDMX, and for the DbContext folder, I have a DbContext generator T4 template setup. Whenever I try to run my DbContext samples, I get an error saying "Could not find the conceptual model type for X", that it can't load the metadata for an entity defined in the EntityFramework folder's EDMX... Why in the world would it do that? I did not setup any T4 template for the EDMX in the EntityFramework folder, and

Entity Framework 4.3 Code First Cannot Create Datetime2?

别说谁变了你拦得住时间么 提交于 2019-12-12 09:37:49
问题 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

How to cleanly generate POCO classes from existing database using Entity Framework 4.3 Code First approach?

♀尐吖头ヾ 提交于 2019-12-11 09:37:33
问题 I'm following the EF Code-First approach in a project that works against an existing database, to which I'm adding tables as needed. This database has a number of tables for which I need to generate POCO classes for, and so I was wondering if there was a straight-forward, clean approach, to generating simple POCO classes from the database ... from which I can continue to work with using the general Code-First paradigm? 回答1: You can use the Entity Framework Power Tools for that. 回答2: If you

MySQL/Writing file error (Errcode 28) on creating database

耗尽温柔 提交于 2019-12-11 05:42:10
问题 I have the following error on execute sql file or creating database by entity framework code first approach Error writing file '.\dbdemo\ads.frm' (Errcode: 28) On local database server it is working fine and creating database by EF Code First Approach but on my website hosting server facing this problem.I have tried both techniques by executing sql file and creating database EF Code First Approach both failed. Any idea how to solve this error ! 回答1: Use the perror command: $ perror 28 OS

Index already exists error in EF 4.3 Code First with Data Annotations

我的未来我决定 提交于 2019-12-11 04:18:39
问题 I'm trying to create a billing database with Entity Framework 4.3 using Code First with Data Annotations, and I'm getting an error every time I try to create my database. Here are the objects that I'm dealing with: public class ClientBase { [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int ClientID { get; set; } [Required] public string ClientName { get; set; } [Required] public bool IsActive { get; set; } [Required] public string ClientContactName { get; set; } [Required]

EFCodeFirst : The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects

£可爱£侵袭症+ 提交于 2019-12-11 03:07:55
问题 I am trying to find out what is causing this error, I have listed some of the relevant areas of my code that should hopefully help answer my problem. The recipe entity's members collection is as shown below: public virtual IList<Member> Members { get; set; } and here is the Recipes collection on the member entity: public virtual IList<Recipe> Recipes { get; set; } I do the below when creating my DbContext in order to make a many-to-many relationship in a separate table protected override void

EF 4.3.1 How to map a sub sub class with table per type

允我心安 提交于 2019-12-11 02:21:29
问题 I have an abstract base class called Party. There are several concrete subclasses (Company, Person, Department). Party has a property called PartyType which is use as the discriminator. Each type is in its own table with configurations like Map<Person>(p => p.Requires("PartyType").HasValue("Person").ToTable("People"); Everything works well. Now I want to add a subclass of Person called Employee. How do I map this? I've tried Map<Employee>(e => e.Requires("PartyType").HasValue("Employee")

Error Remapping EF Code First TPH Discriminator

混江龙づ霸主 提交于 2019-12-10 18:36:53
问题 I'm attempting to remap the descriminator column of my TPH-persisted object hierarchy as described at: http://msdn.microsoft.com/en-us/library/hh295845(v=vs.103).aspx http://blogs.msdn.com/b/adonet/archive/2010/12/14/ef-feature-ctp5-fluent-api-samples.aspx https://stackoverflow.com/a/6650064/141172 When I map using either of the following variants: modelBuilder.Entity<MyBase>() .Map<MyBase>(m => m.Requires("TypeId").HasValue(0)) .Map<DerivedA>(m => m.Requires("TypeId").HasValue(1)) .Map