code-first

How do I get Entity Framework 4.3 Code First to map a subclass using Table Per Type (TPT)?

▼魔方 西西 提交于 2019-12-23 02:57:06
问题 I'm using EF 4.3 Code First and automatic migrations. I have the following 3 classes: public class BaseUser { [Key] [MaxLength(50)] public string Username { get; set; } [MaxLength(200)] public string Password { get; set; } } public class AdminUser : BaseUser { public int SettingsFlag { get; set; } } public class RegularUser : BaseUser { public DateTime LastLogin { get; set; } public DateTime LastSummary { get; set; } [MaxLength(100)] public string Email { get; set; } public int CompanyID {

Second database created with MVC3, how to prevent?

╄→гoц情女王★ 提交于 2019-12-22 08:59:23
问题 I'm very new to MVC 3 and I'm having problem with the Code First approach. I created 2 models, a context, view, etc and everything works perfect (able to add, delete, etc.) But when I check in Microsoft SQL Management Studio, I see 2 databases. One of them is the one I asked for in my web.config. This one contain only the membership table <connectionStrings> <add name="RecettesMaison" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=RecettesMaison;User Id=user;Password=password;"

EF Linq to entities query generating UNION for TPC CTP5 code-first entity

青春壹個敷衍的年華 提交于 2019-12-22 08:52:33
问题 I have the following entities: public class User { public int Id { get; set; } public string Name { get; set; } } public class HappyUser : User { public bool IsHappy { get; set; } } I am configuring the entities using Table Per Concrete Type (TPC) in order to generate a User table and a HappyUser table. I want the HappyUser table to include the properties of the User class, and I don't want any relationship between the two tables. I configure the entities as follows: public class UserTest :

EF Codefirst validate unique property?

此生再无相见时 提交于 2019-12-22 04:21:27
问题 Curious about how to efficiently validate that a given property of a CodeFirst model is unique. Classic example being a member's username or display name. Traditionally I might do this by setting a Unique constraint in the database, or alternatively by doing a lookup during an attempted insert operation. I know how to manually add these things in the DB itself after generation, just wanting to see if there's a way to do it as part of the schema mapping provided by the framework. UPDATE I

EF Codefirst validate unique property?

人走茶凉 提交于 2019-12-22 04:21:02
问题 Curious about how to efficiently validate that a given property of a CodeFirst model is unique. Classic example being a member's username or display name. Traditionally I might do this by setting a Unique constraint in the database, or alternatively by doing a lookup during an attempted insert operation. I know how to manually add these things in the DB itself after generation, just wanting to see if there's a way to do it as part of the schema mapping provided by the framework. UPDATE I

Column names in each table must be unique. Column name 'StripeRecipientId' in table 'dbo.Foos' is specified more than once

断了今生、忘了曾经 提交于 2019-12-22 04:05:36
问题 I have a model class named Foo that has, among others, these properties. public string StripeRecipientId { get; set; } public override bool HasProvidedBillingInformation { get { // return !string.IsNullOrEmpty(this.StripeRecipientId); return false; } } I have enabled migrations and am using Code First. When I run the update-database commandlet, whether with -Force option is specified or not, I get this error: Column names in each table must be unique. Column name 'StripeRecipientId' in table

DbContext's ChangeTracker problem

时光总嘲笑我的痴心妄想 提交于 2019-12-22 01:37:06
问题 I have a codefirst EF-4.1 based program. The user gets a context and can modify some properties. When the user is done, I do a quick ChangeTracker.Entries().Any(e => e.State != EntityState.Unchanged); to determine if a SaveChanges() is required or not. If I do a 'SaveChanges()' call, the changes that have made are persisted to the database. This works for some properties, and doesn't work for others. Specifically it seems to work with simple types ( float s), and with collection hierarchies(

How to add a column to a link table with code first

你说的曾经没有我的故事 提交于 2019-12-21 21:56:30
问题 I have a ResearchDatabase entity that has a many-to-many relationship with a Subject entity. i.e. a Research Database belongs in one or more Subject Categories, and a Subject Category contains one or more Research Databases. In my ResearchDatabaseConfiguration file I have the following mapping: HasMany(rd => rd.Subjects) .WithMany(s => s.ResearchDatabases) .Map(m => { m.MapLeftKey("DatabaseId"); m.MapRightKey("SubjectId"); m.ToTable("DatabaseSubjects"); }); OK, no problem. Works. Creates a

First try StructureMap and MVC3 via NuGet

断了今生、忘了曾经 提交于 2019-12-21 14:36:13
问题 I'm trying to figure how to config StructureMap for ASP.NET MVC3 I've already using NuGet and I notice that it creates App_Start Folder with a cs file named as StructuremapMVC, so I check it and notice that is the same code but simplified that will be written manually on App_Start section placed on Global.asax... This is my code from IoC Class public static class IoC { public static IContainer Initialize() { ObjectFactory.Initialize(x => { x.Scan(scan => { scan.TheCallingAssembly(); scan

How can I implement DBSet.AddOrUpdate in Entity Framework 4.4?

允我心安 提交于 2019-12-21 07:15:22
问题 In response to Slauma's answer to my question about running applications that use EF on Windows XP I am converting my application back from Entity Framework 5.0 to use Entity Framework 5.0 and target framework .NET 4.0 (Also called Entity Framework 4.4) However I encounter the following error; System.Data.Entity.DbSet<MyEntity> does not contain a definition for AddOrUpdate and no extension method of a type System.Data.Entity.DbSet<MyEntity> accepting a first argument of type System.Data