ef-code-first

EF6 Code first “model backing DataContext has changed” error (.mdf Db)

不想你离开。 提交于 2019-12-10 11:45:22
问题 I'm new to the code first methodology. I'm getting this error: "The model backing the 'DataContext' context has changed since the database was created. Consider using Code First Migrations to update the database". I have a WPF app using EF6 & MVVM running against a local db (.mdf life). I created a new model, called langauges then I added a new DbSet< langauges > collection to my datacontext. When the code tries to instantiate the a datacontext object, I get the error above. What am I missing

Is it possible to create User-Defined Data Types when using EF 4.1 Code First?

谁说胖子不能爱 提交于 2019-12-10 11:41:32
问题 When using EF 4.1 Code First, is it possible to create User-Defined Data Types for your schema? 回答1: Simple answer is no. Longer answer: Current EF implementation leads to multiple issues when trying to use user defined types: The type must be defined prior to its usage in table's DDL definition. Because of that the type cannot be defined in Seed method of database initializer (as often used for other database constructs like triggers or indexes). To make this work you must create whole new

EF Code First working with many-to-many relationships

佐手、 提交于 2019-12-10 11:36:46
问题 I am using Visual Studio 2010, C# 4.0 and Entity Framework 5.0. I have been using database first development for many years but am trying to move to code first and am running into problems. Reading and searching does not seem to address the problems I have simplified my problem as follows - I have two classes - Assessors and Documents. public class Assessor { public int AssessorID { get; set; } public virtual List<Document> Documents { get; set; } } public class Document { public int

Entity Framework 4.1 Code First Freeze

拥有回忆 提交于 2019-12-10 11:34:53
问题 I'm having trouble getting EF 4.1 working on my computer. It seems to be some problem with my database settings. I was trying out this simple walkthrough: http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-code-first-walkthrough.aspx But when it reaches db.Categories.Add(food); it just freeze. I have a normal SQL Server 2008 R2 installed, not SQL Express. There also seems to be some problems with creating .mdf files instead of a direct connection to the localhost SQL server. I've also

How to use DbContext when there is no DbSet<> inside that, for query?

天涯浪子 提交于 2019-12-10 11:23:58
问题 I'm using Entity Framework Code-First and this is my DbContext . As you see there is nothing about DbSet<> properties and all of that will provide from my model classes which are providing by C# CodeDOM . I'm creating my Tables dynamically by using Code-First . public class MyDBContext : DbContext { public MyDBContext() : base("MyCon") { Database.SetInitializer<MyDBContext>(new CreateDatabaseIfNotExists<MyDBContext>()); } protected override void OnModelCreating(DbModelBuilder modelBuilder) {

Code First migrations updating the wrong Db on localdb

旧巷老猫 提交于 2019-12-10 11:17:30
问题 I am using code first migrations to create and update the database for my asp mvc site. I have a DbContext, which is in another project in the solution. public class EFDbContext : DbContext { public DbSet<Book> Books { get; set; } public DbSet<Author> Authors { get; set; } public DbSet<Publisher> Publishers { get; set; } } When i enable-migrations and add-migration [name] . It seems to create its own db called [foo-projectname].Domain.Concrete.EFDbContext Instead of the attaching to the

Visual Studio 2015 debugging issues

爷,独闯天下 提交于 2019-12-10 10:52:26
问题 Every time I try to debug anything in c# asp.net I get this error. Error = Unable to evaluate the expression. Operation not supported. Unknown error: 0x80070057. alongside something like this Local = Evaluation of method System.Data.Entity.DbSet`1[appname.DataLayer.Entities.GameResultEntity].get_Local() requires use of the static field System.Data.Entity.Infrastructure.DbContextInfo._currentInfo, which is not available in this context. In this case, all I'm doing is adding something to the

Unidirectional association with WillCascadeOnDelete

时光怂恿深爱的人放手 提交于 2019-12-10 10:49:10
问题 I have a very simple unidirectional class mappings. public class MyDbContext : DbContext { public MyDbContext() : base("CodeFirstDatabase") { } public DbSet<Contact> Contacts { get; set; } public DbSet<PhoneNumber> Number { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); modelBuilder.Conventions.Remove<IncludeMetadataConvention>(); modelBuilder.Entity<Contact>() .HasMany(c => c.Numbers)

How to create and use a generic class EntityTypeConfiguration<TEntity>

随声附和 提交于 2019-12-10 10:36:35
问题 Code I have two very simple interfaces in my application Represents entities that are saved in the database public interface IEntity { int Id { get; set; } } Entities that have only the Nome field as required field to save the entity public interface IEntityName : IEntity { string Nome { get; set; } } And many classes implementing this interface public class Modalidade : IEntityName { public int Id { get; set; } public string Nome { get; set; } } public class Nacionalidade : IEntityName {

Entity CodeFirst EF6, EntityData string id

孤者浪人 提交于 2019-12-10 10:25:13
问题 Have started to use Entity Code First with Azure Mobile Services and have met some issue: For using TableController with Entity objects I need to derive each of them from EntityData class, that provide string Id field! I used to use int, long and even guid instead string for id, so... What is benefits of this? What about insert operation and what is the best practice for this? What about performance for string id? 回答1: @carlosfigueira has a good writeup about the change to using string id