entity-framework-5

How to use an existing enum with Entity Framework DB First

限于喜欢 提交于 2019-11-30 00:02:35
I am using Entity Framework 5, DB first. I know how to define an enum on my model, and set the type of a field to that enum. Now, I have a requirement to map a field MyField to an enum that is defined externally, i.e. not in the EF model ( OtherNamespace.MyEnum ). The designer does not allow me to set the type to anything outside the model. I tried editing the edmx file manually, but that causes an error: Error 10016: Error resolving item 'MyField'. The exception message is: 'Unresolved reference 'OtherNamespace.MyEnum'.'. OtherNamespace.MyEnum is referenced by my project. How do you do it?

Why am I getting an IdentityRole error?

随声附和 提交于 2019-11-29 23:45:24
问题 Using Identity 2.0 After registering a user, the user is created in the database, there is code in the Account controller to create an identity and sign the user in. This is when I get the error. Here is the code producing the error: var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); And here is the error: The entity type IdentityRole is not part of the model for the current context. My Model looks like this: namespace MyApp.Models {

How does Database.SetInitializer actually work? (EF code-first create database and apply migrations using several connection strings)

隐身守侯 提交于 2019-11-29 22:55:34
问题 I am trying to write a method to create a database and run migrations on it, given the connection string. I need the multiple connections because I record an audit log in a separate database. I get the connection strings out of app.config using code like ConfigurationManager.ConnectionStrings["Master"].ConnectionString; The code works with the first connection string defined in my app.config but not others, which leads me to think that somehow it is getting the connection string from app

How to set up LocalDb for unit tests in Visual Studio 2012 and Entity Framework 5

杀马特。学长 韩版系。学妹 提交于 2019-11-29 20:50:21
We have a Visual Studio 2012 ASP.NET MVC project using Entity Framework 5. There are some unit tests that depend on a database. Setting up the app.config file in the test project to use a central SQL Server database works fine. However, it would be much nicer to use a LocalDb, so that each developer has his/her own database when running the tests. Especially since we would like to have the tests set up to DropCreateDatabaseAlways when running. However, I can't get the setup to work. If I try this in app.config: <add name="TestDb" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog

Entity Framework 5: Using DatabaseGeneratedOption.Computed option

柔情痞子 提交于 2019-11-29 17:45:45
问题 I have an EF5 code first project that uses the [DatabaseGenerated(DatabaseGeneratedOption.Computed)] attribute. This option is overriding my settings. Consider this SQL table: CREATE TABLE Vehicle ( VehicleId int identity(1,1) not null, Name varchar(100) not null default ('Not Set') ) I am using the SQL default construct to set the [Name] is case it is not set. In code behind, I have a class defined similar to: public class Vehicle { ... [DatabaseGenerated(DatabaseGeneratedOption.Computed)]

User has roles for systems - how to (object-)model ternary relation?

两盒软妹~` 提交于 2019-11-29 17:28:12
I've got the following Entities: Privilege ( Id, Name ) Role ( Id, Name, ICollection<Privilege> ) System ( Id, Name ) User ( Id, Name, Pass, ? ) Now I want to model "A user may have for each of zero or more systems zero or more roles", e.g.: IDictionary<System, ICollection<Role>> SystemRoles { get; set; } Is this possible with ASP.NET EntityFramework? If yes, how? What attributes do I have to set? Been looking around for quite some time now, however I don't find anything useful on the net for "entity framework code first ternary relation" Can you point me to some nice link where this is

Entity Data Model Wizard Too Slow (SQL Database)

一笑奈何 提交于 2019-11-29 17:26:46
问题 Using: visual studio 2012 Ultimate, ADO Entity Framework 6, Database: Sql express 2014 (installed on local PC), Database tables count: 174 table. I am trying to create database model using Entity Data Model Wizard but it takes about 8 hours to create the model(Dialog not responding). I tried to reinstall visual studio & Entity Framework but the same problem. I need any ideas that can speed up database model creation. 回答1: Updating to Cumulative update package 5 for SQL Server 2014 fixes this

Attribute [Bind(Exclude=“”)] fails to prevent over-posting

心不动则不痛 提交于 2019-11-29 15:39:49
问题 What is the best way to prevent MVC 4 over-posting? According to MS sources, the [Bind] attribute is supposed to be the easiest way to prevent over-posting by preventing incoming form values from making it to the database. With the latest version of MVC & EF this does not seem to be working as expected/advertised, unless I'm missing something major. From Wrox Professional ASP.NET MVC 4 (Jon Galloway's Chapter 7), the following class should prevent over-posting: [Bind(Exclude="IsAdmin")]

MVC “create view” when there is one to many relationship in model

别来无恙 提交于 2019-11-29 15:31:08
问题 My model is simple, one client can have many phone numbers : I have represented this in Entity Framework Generated client class is as below. public partial class Client { public Client() { this.PhoneNumbers = new HashSet<PhoneNumber>(); } public int Id { get; set; } public string Name { get; set; } public virtual ICollection<PhoneNumber> PhoneNumbers { get; set; } } And now I need to create a view page for "create client". This page should have space to enter PhoneNumbers also (ex: By default

Entity Framework Code First 5 Cascade Delete on many to many tables error

心已入冬 提交于 2019-11-29 14:19:36
问题 I've this model public class State { public State() { this.Promotions = new List<Promotion>(); this.Branches = new List<Branch>(); this.Stores = new List<Store>(); } public int Id { get; set; } public string Description { get; set; } public virtual ICollection<Promotion> Promotions { get; set; } public virtual ICollection<Store> Stores { get; set; } public virtual ICollection<Branch> Branches { get; set; } } public class Store { public Store() { this.Promotions = new List<Promotion>(); this