entity-framework-5

Entity Framework 5 expects CreatedOn column from MigrationHistory table

喜你入骨 提交于 2019-12-18 18:46:08
问题 I am migrating an MVC 3 application from EF 4.3 to EF 5. I noticed that EF 5 expects a CreatedOn column in the __MigrationHistory table, which does not exist as the migrations were created by an older version. SELECT TOP (1) [c].[CreatedOn] AS [CreatedOn] FROM [dbo].[__MigrationHistory] AS [c] How do I resolve this issue without wiping my migration history? I am thinking of a query to infer the column's value from the migration name, which is in the following format: 201203111201542

Pros and Cons of putting a db context in static class library

◇◆丶佛笑我妖孽 提交于 2019-12-18 15:54:47
问题 We have a static class library to deal with repeated multi-contextual tasks. Is it bad practice to create an EF db context as member of a static class? DB contexts are meant to be disposed of for a reason. Having them disposed frequently keeps the connection pool "flowing" and probably (here I'm speculating) assures that tables don't remain locked. So am I inviting trouble having a db context in a static class or am I overthinking this? 回答1: IMO this is definitally not something you want to

No context type was found in the assembly

不羁的心 提交于 2019-12-18 12:47:28
问题 I'm using .NET 4.0, MVC3, and EF5 with code first. My solution is split up into three projects, with the dependencies as indicated: Project.Web -> Project.BLL -> Project.DAL The Project.DAL layer contains my entity framework data context class and all my entities, but my startup project is Project.Web, so it contains my Web.config, connection strings, and the actual SQL compact database. I'm trying to enable migrations so I can add a new table to my EF model without wiping the existing data.

entity framework 5 MaxLength

ぃ、小莉子 提交于 2019-12-18 11:26:39
问题 I was using EF4 and a piece of code I found to get the MaxLength value from an entity like this: public static int? GetMaxLength(string entityTypeName, string columnName) { int? result = null; using (fooEntities context = new fooEntities()) { Type entType = Type.GetType(entityTypeName); var q = from meta in context.MetadataWorkspace.GetItems(DataSpace.CSpace) .Where(m => m.BuiltInTypeKind == BuiltInTypeKind.EntityType) from p in (meta as EntityType).Properties .Where(p => p.Name == columnName

entity framework 5 MaxLength

岁酱吖の 提交于 2019-12-18 11:26:01
问题 I was using EF4 and a piece of code I found to get the MaxLength value from an entity like this: public static int? GetMaxLength(string entityTypeName, string columnName) { int? result = null; using (fooEntities context = new fooEntities()) { Type entType = Type.GetType(entityTypeName); var q = from meta in context.MetadataWorkspace.GetItems(DataSpace.CSpace) .Where(m => m.BuiltInTypeKind == BuiltInTypeKind.EntityType) from p in (meta as EntityType).Properties .Where(p => p.Name == columnName

Migration does not alter my table

倾然丶 夕夏残阳落幕 提交于 2019-12-18 09:30:06
问题 I just enabled migrations in my project and added a few fields to UserProfile : [Table("UserProfile")] public class UserProfile { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int UserId { get; set; } public string UserName { get; set; } public string Email { get; set; } public string Description { get; set;} public DateTime? CreatedOn { get; set; } public DateTime? LastAccess { get; set; } } I Add-migration AddFieldsForUserProfile and it created: ... public

C# How to serialize system.linq.expressions?

不羁岁月 提交于 2019-12-18 09:07:08
问题 I am working on winRT and entity framework (to SQL), the layer that communicates between them is WCF Service. In the entity framework I am using the Repository Pattern and I have the method: public IQueryable<User> GetBySearch(Expression<Func<User, bool>> search) { return this.Context.Users.Where(search); } Everything works fine, but when I add it to WCF [OperationContract] IQueryable<User> GetUserBySearch(Expression<Func<User, bool>> search); and: public IQueryable<User> GetUserBySearch

'Enable-Migrations' fails after upgrading to .NET 4.5 and EF 5

谁都会走 提交于 2019-12-18 07:35:15
问题 I just upgraded my MVC4 project to .NET 4.5 and EF5 and started using VS2012. After realizing I needed to set-up auto-migrations in the Package Manager again I ran Enable-Migrations - EnableAutomaticMigrations and received the error No context type was found in the assembly 'MySolutionName'. Some Research has said that it has to do with EF5 not enabling prereleases. I ran Install-Package EntityFramework -IncludePrerelease but it said EF5 was already installed (which it was when I installed it

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

'Enable-Migrations' fails after upgrading to .NET 4.5 and EF 5

懵懂的女人 提交于 2019-12-18 07:34:59
问题 I just upgraded my MVC4 project to .NET 4.5 and EF5 and started using VS2012. After realizing I needed to set-up auto-migrations in the Package Manager again I ran Enable-Migrations - EnableAutomaticMigrations and received the error No context type was found in the assembly 'MySolutionName'. Some Research has said that it has to do with EF5 not enabling prereleases. I ran Install-Package EntityFramework -IncludePrerelease but it said EF5 was already installed (which it was when I installed it