ef-code-first

How to make Fluent API configuration work with MVC client side validation?

自作多情 提交于 2019-12-18 11:18:43
问题 I prefer working with Fluent API configuration to DataAnnotation because I want to separate model from data access. I have tried in MVC, Fluent API does not work with client side validation. Shortly speaking, is there a simple way to make Fluent API works with client side validation as DataAnnotation can do? 回答1: No. Fluent API is just mapping - correct. Data annotations are both mapping and validation - wrong. Data annotations are one of the worst features of EF code first because when used

What does WebActivator do?

╄→尐↘猪︶ㄣ 提交于 2019-12-18 10:59:28
问题 This code was generated for me after added entity framework code-first for SQL Server CE using NuGet. They did no changes to any other file. The file SQLCEEntityFramework.cs was created and placed in App_Start folder. Does this mean it automatically gets executed or something? The same thing happened when I added Ninject for MVC 3. No code was added to the global.ascx file so I have no idea if its plug and play or I have to configure something. [assembly: WebActivator

What does WebActivator do?

徘徊边缘 提交于 2019-12-18 10:58:59
问题 This code was generated for me after added entity framework code-first for SQL Server CE using NuGet. They did no changes to any other file. The file SQLCEEntityFramework.cs was created and placed in App_Start folder. Does this mean it automatically gets executed or something? The same thing happened when I added Ninject for MVC 3. No code was added to the global.ascx file so I have no idea if its plug and play or I have to configure something. [assembly: WebActivator

Code First Migrations and initialization error

[亡魂溺海] 提交于 2019-12-18 10:35:20
问题 I'm unsure about how to use the code first migration feature. In my understanding it should create my database if it's not existing already, and update it to the latest schema according to migration files. But I'm struggling with it, because I always get a lot of errors and I'm unsure overall how to use this properly.. internal class Program { private static void Main() { EntityFrameworkProfiler.Initialize(); Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data

How to sync model after using Code First from Database using Entity Framework 6.1 and MVC 5?

半腔热情 提交于 2019-12-18 10:03:18
问题 Assumptions Using EF 6.1, MVC 5, VS 2013, C# I have an existing database model designed in Toad DM for SQL Server and it's very important keep it always updated Steps and Notes Using ADO.NET Entity Data Model I chose Code First from Database ( new feature in EF 6.1 ) to generate the models. Note: Model classes and DbContext class generated successfuly but NO .edmx or .tt file was generated . Next I added a new scaffold item: MVC 5 Controllers with views, using Entity Framework. Note: Success,

Entity Framework - Remove object with foreign key, preserving parent

折月煮酒 提交于 2019-12-18 09:49:46
问题 I have have the following models: public class Company { //Primary key public string ID { get; set; } //Foreign key public int? LogotypeID { get; set; } } and public class Logotype { //Primary key [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int? ID { get; set; } //Foreign key public string CompanyID { get; set; } } How do I delete the logotype from the Company table, without removing the company row? Using: http://msdn.microsoft.com/en-us/library/system.data.entity.dbset

How to correctly set foreign key constraint in one to many relationship in code first ASP.NET MVC 5 application

核能气质少年 提交于 2019-12-18 09:39:26
问题 So I have one document table and a ApplicationUser table. One user can upload multiple documents and a foreign key constraint has been applied accordingly using the code first approach. But the problem is, I am able to save the document without assigning the UserID foreign key id in the Documents table . What am I missing here? Below is my novice attempt. ApplicationUser Model: it's the standard model provided by the framework. Document Model: public class Document { public int Id { get; set;

What could cause many data access exceptions using EF code first in a custom RoleProvider?

人盡茶涼 提交于 2019-12-18 09:27:15
问题 My role provider looks like the class below (abridged). I am running on IIS Express, and SQL 2012 Express, from VS 2012, and I get a multitude of seemingly random exceptions in this role provider code. public class Educ8RoleProvider : RoleProvider { private readonly Educ8DbContext _dbContext = new Educ8DbContext(); private readonly Authorization _authorization; public Educ8RoleProvider() { _authorization = new Authorization(_dbContext); } public override void Initialize(string name, System

How do I set Identity seed on an ID column using Entity Framework 4 code first with SQL Compact 4?

痴心易碎 提交于 2019-12-18 09:15:33
问题 I am having some problem setting the Identity Seed on the Id column in SQL Compact 4 using the code first approach. I have tried this context.Database.ExecuteSqlCommand("DBCC CHECKIDENT ('Members', RESEED, 100001"); but this is not working in Sql Compact. MyDbContext: protected override void OnModelCreating(DbModelBuilder modelBuilder) { SetupMemberEntity(modelBuilder); } private static void SetupMemberEntity(DbModelBuilder modelBuilder) { modelBuilder.Entity<Member>().Property(m => m.Id); //

Entity Framework Code First Self Referencing Parent Child with Payload

故事扮演 提交于 2019-12-18 08:29:44
问题 I'm attempting to set this up using code first in entity framework and am running into difficulty. To describe what i'm trying to accomplish: Have an entity of Product. This product optionally may have one or more related "child" products. A product can be the child to one or more parent products. when I go to generate a controller tied to the model class "Product", i'm getting an error: (updated, more specific, matches code below) There was an error running the selected code generator: