code-first

Entity Framework Code First Data Migrations not working with VS2012 Web Deploy

匆匆过客 提交于 2019-12-04 03:02:40
I have created an MVC 3.0 application using Visual Studio 2012, .NET 4.5 and Entity Framework 5.0. Using Code First Data Migrations, I am able to correctly propagate model changes to my local test database, but I can't figure out how to get this to work when deploying to my staging and production servers using Web Deploy. I have read the following article ... http://msdn.microsoft.com/en-us/library/dd394698(v=vs.110)#dbdacfx ... which explains what's supposed to happen, but it's not working for me, as Web Deploy seems unable to detect that I am using Entity Framework. The tutorial shows a

EntityFramework Mutli-Table Many-to-Many

雨燕双飞 提交于 2019-12-04 02:35:39
问题 I'm working with EF4.1 Code First and am trying to create some Many-to-Many relationship tables where there tables would need to be linked. Please see small snippet of code beloow: class Event { int EventId { get; set; } ICollection<Contact> Contacts { get; set; } } class Contact { int ContactId { get; set; } ICollection<Relation> Relations { get; set; } } class Relation { int RelationId { get; set; } string Name { get; set; } } So the Contacts object can have many different types of

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

不想你离开。 提交于 2019-12-04 01:53:00
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.Entity.DbSet<MyEntity> could be found. (Are you missing a using directive or assembly reference ) I have

code first membership provider

你离开我真会死。 提交于 2019-12-03 22:01:39
How can I integrate EF 5.0 with membership provider using code first? I have my own database schema which I want to use for registration of users etc. You should take a look at the SimpleMembershipProvider It is very easy to use it together with EF. Update For MVC4 I would start with the blank template. you need WebSecurity.InitializeDatabaseConnection to set up the database. WebSecurity.InitializeDatabaseConnection("DefaultConnection", "Users", "Id", "UserName", true); It takes as parameters a name of a connectionstring, the table, a unique identifier column and the username-column. The model

How can I use TPT inheritance models when primary keys have different names?

社会主义新天地 提交于 2019-12-03 20:31:22
问题 Using Entity Framework 4.1 against a legacy database, I'm unable to generate a working set of TPT inheritance models that aren't pluralized and use different names for a common primary key. I am using database tables Organization, Account, and Company as illustrated below: Organization OrganizationID (int PK) OrgName (varchar) Company CompanyID (int PK) CompanyNo (varchar) Account AccountID (int PK) AccountNo (varchar) Account.AccountID and Company.CompanyID have a FK constraint that values

How do you minimize the performance hit when upgrading to EF 4.1 from LINQ to SQL?

随声附和 提交于 2019-12-03 17:15:54
I recently updated an app with LINQ to SQL and SQL Server CE 3.5 to Entity Framework 4.1 Code First and SQL Server CE 4.0, and it's now running noticeably slower. I did some before vs. after stopwatch testing, and most major operations of my app appear to be running about 40% slower on average. I'm using all default strategies and configurations for EF Code First except for disabling cascading deletes. When I originally posted this question, I was focused on one query that seemed to be taking particularly long, but I've since realized that it was only particularly slow on first run (see the

EF6 CodeFirst My [Key] Id Column is not auto-incrementing as an identity column should

匆匆过客 提交于 2019-12-03 16:34:26
问题 I have several classes that I need to derive from a common base class which holds an Id. Ignoring the all but one of these for the moment, let's say we have: public class MyBase { [Key] public int Id { get; set; } } public class MyName : MyBase { public string Name { get; set; } } my context (DataContext) looks like this: public DbSet<MyName>MyNames { get; set; } // to avoid having EF make a MyBases table and instead map // MyBase.Id into MyNames and my other derived classes I do this ...

Entity Framework, Code First, Update “one to many” relationship with independent associations

主宰稳场 提交于 2019-12-03 16:23:17
问题 It took me way too long to find a solution to the scenario described below. What should seemingly be a simple affair proved to be rather difficult. The question is: Using Entity Framework 4.1 (Code First approach) and "Independent associations" how do I assign a different end to an existing "many to one" relationship in a "detached" scenario ( Asp.Net in my case). The model: I realize that using ForeignKey relationships instead of Independent Associations would have been an option, but it was

Entity Framework Code First - Configuration in another file

你。 提交于 2019-12-03 15:52:03
What is the best way to separate the mapping of tables to entities using the Fluent API so that it is all in a separate class and not inline in the OnModelCreating method? What I am doing currently: public class FooContext : DbContext { // ... protected override OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<Foo>().Property( ... ); // ... } } What i want: public class FooContext : DbContext { // ... protected override OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.LoadConfiguration(SomeConfigurationBootstrapperClass); } } How do you do this? I am using C#. You

Use ASP.NET Membership in ServiceStack

≯℡__Kan透↙ 提交于 2019-12-03 15:15:11
how can i use asp.net membership in ServiceStack ? (ServiceStack.OrmLite , ServiceStack.Host.AspNet , etc ) mythz You can host ServiceStack on a custom path , i.e. at /api which lets you run ASP.NET web forms and ServiceStack side-by-side and then use the normal ASP.NET membership provider in ASP.NET. You can then share UserSessions with ServiceStack using its Session Provider, here's an example on how to instantiate a Session with MVC - you can use this same class with ASP.NET. The alternative is to forgo the ASP.NET membership provider and just stick to the built-in authentication in