ef-code-first

ef 5 codefirst enum collection not generated in database

不打扰是莪最后的温柔 提交于 2019-12-18 08:29:24
问题 I am using EF5 and .NET 4.5. I have one particular class that is being generated incorrectly in the database. Although it is somewhat more complicated in my website, I'll simplify; namespace Store.Enities { public enum Role { Manager, Clerk } public class User { public int Id {get; set;} public ICollection<Role> Roles {get; set;} } public class StoreContext : DbContext { public DbSet<User> Users {get; set;} public StoreContext() { Database.SetIntializer(new DropCreateDatabaseIfModelChanges

Getting 'Context is not constructible. Add a default constructor or provide an implementation of IDbContextFactory."

ぐ巨炮叔叔 提交于 2019-12-18 07:35:02
问题 I am getting this error when I try to use code first migrations. My context has a constructor with the connection name. public class VeraContext : DbContext, IDbContext { public VeraContext(string NameOrConnectionStringName = "VeraDB") : base(NameOrConnectionStringName) { } public IDbSet<User> Users { get; set; } public IDbSet<Product> Products { get; set; } public IDbSet<IntCat> IntCats { get; set; } } This connection name is injected with ninject when the project runs, I have also specified

Getting 'Context is not constructible. Add a default constructor or provide an implementation of IDbContextFactory."

末鹿安然 提交于 2019-12-18 07:34:20
问题 I am getting this error when I try to use code first migrations. My context has a constructor with the connection name. public class VeraContext : DbContext, IDbContext { public VeraContext(string NameOrConnectionStringName = "VeraDB") : base(NameOrConnectionStringName) { } public IDbSet<User> Users { get; set; } public IDbSet<Product> Products { get; set; } public IDbSet<IntCat> IntCats { get; set; } } This connection name is injected with ninject when the project runs, I have also specified

Complex Type Ignored by Entity Framework Code First

半世苍凉 提交于 2019-12-18 07:05:13
问题 Building on Ladislav's answer to Entity Framework Code First and Collections of Primitive Types I'm attempting to create a wrapper type EfObservableCollection<T> around an ObservableCollection<T> that has an additional helper property to simplify persistence (certainly this solution has trade-offs, but it's seems workable for my domain). However, properties of type EfObservableCollection<T> seem to be ignored by EF. No appropriate columns are created in the database. Guessing that

ef code first: get entity table name without dataannotations

梦想的初衷 提交于 2019-12-18 06:57:30
问题 Is there a way to get table info defined with DbModelBuilder? something like: entity.GetType().GetTableName() Max EDIT: id like to implement following public static class Helper { public string GetTableName(Type type) { // ?? } } now i'd like to get table name by type var type = someEntity.getType(); var sql = "delete from " + Helper.GetTableName(type) + " where id in (...)" 回答1: Only solution i can imagine is reflection. Here it is protected override void OnModelCreating(DbModelBuilder

SSDT on Visual Studio 2012 broken then fixed, broken again also broken on VS2013

。_饼干妹妹 提交于 2019-12-18 06:48:36
问题 After installing Visual Studio 2012 Ultimate on Windows 8, SSDT via SQL Server Object Explorer did not work. The solution was to install the latest version of VS2012 from the MSDN website. All was well. I could see databases, no problem. It did not matter whether I used the EF defaultConnectionFactory or my own connectionString, either way, all of my code first databases showed up in the VS2012 SQL Server Object Explorer. Not long ago, I installed Visual Studio 2013 Ultimate. In VS2013

Entity Framework - Reuse Complex Type

陌路散爱 提交于 2019-12-18 06:09:07
问题 I have an Entity in Code First Entity framework that currently looks like this: public class Entity { // snip ... public string OriginalDepartment { get; set; } public string OriginalQueue { get; set; } public string CurrentDepartment { get; set; } public string CurrentQueue { get; set; } } I would like to create Complex Type for these types as something like this: public class Location { public string Department { get; set; } public string Queue { get; set; } } I'd like to use this same type

Why does code first/EF use 'nvarchar(4000)' for strings in the raw SQL command?

徘徊边缘 提交于 2019-12-18 05:56:31
问题 Essentially I have a table with zip codes in it. The zipcode field is defined as 'char(5)'. I'm using code first, so I've put these attributes on my ZipCode property: [Key, Column( Order = 0, TypeName = "nchar"), StringLength(5)] public string ZipCode { get; set; } Now if I query against this in EF: var zc = db.ZipCodes.FirstOrDefault(zip => zip.ZipCode == "12345"); The generated SQL uses nvarchar(4000) to inject the parameters. Huh? Is it because "12345" is technically a string of unknown

The type 'Company.Model.User' and the type 'Company.Core.Model.User' both have the same simple name of 'User' and so cannot be used in the same model

旧街凉风 提交于 2019-12-18 05:27:07
问题 I have a base entity class MyCompany.Core.Model.User which is to be used for common properties of a User entity: public class User { public string Username { get; set; } public string Usercode { get; set; } } I also have a base mapping class MyCompany.Core.Model.UserMap to setup the code first mappings for the base User class: public class UserMap<TUser> : EntityMapBase<TUser> where TUser : User { public UserMap() { // Primary Key this.HasKey(t => t.Usercode); // Table & Column Mappings this

Class Inheritance with .NET EF4.1 + MySQL

我怕爱的太早我们不能终老 提交于 2019-12-18 05:11:30
问题 I'm trying to implement class inheritance in .NET using Entity Framework 4.1 and MySQL as database, with code-first approach. The model below works with SQL Server, but fails in MySQL with the following error: Schema specified is not valid. Errors: (11,6) : error 0064: Facet 'MaxLength' must not be specified for type 'mediumtext'. The model is a classic simple example: public abstract class Vehicle { public int Id { get; set; } public int Year { get; set; } } public class Car : Vehicle {