entity-framework-5

code first membership provider

你离开我真会死。 提交于 2019-12-03 22:01:39
How can I integrate EF 5.0 with membership provider using code first? I have my own database schema which I want to use for registration of users etc. You should take a look at the SimpleMembershipProvider It is very easy to use it together with EF. Update For MVC4 I would start with the blank template. you need WebSecurity.InitializeDatabaseConnection to set up the database. WebSecurity.InitializeDatabaseConnection("DefaultConnection", "Users", "Id", "UserName", true); It takes as parameters a name of a connectionstring, the table, a unique identifier column and the username-column. The model

Entity Framework Poor COUNT Performance

▼魔方 西西 提交于 2019-12-03 21:34:09
问题 We are experiencing very poor performance using Entity Framework 5.0 with MySql Connector 6.6.6.0 for count based queries. Our data structure looks like: Table: Post =========== ID INT PRIMARY KEY MemberID INT NOT NULL SiteID INT NOT NULL Description VARCHAR(255) NOT NULL Image VARCHAR(255) NOT NULL CreatedDate DATETIME NULL And using entity framework with a linq query like the following: var count = entities.Post.Where(p => p.SiteID == 1 && p.CreatedDate != null).Count(); We get the

Why I can't get Entity Framework Migration to initial state?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 21:14:47
I have deleted development database, and Migrations folder from project. When running unit test with use my project development database is recreated. I don't understand why running update-database gives me PM> Update-Database Specify the '-Verbose' flag to view the SQL statements being applied to the target database. Applying code-based migrations: [201302201840012_wieleDoWielu]. Applying code-based migration: 201302201840012_wieleDoWielu. Why migration: 201302201840012_wieleDoWielu is remembered ? How Can I delete it? Where is stored? Best Regards Przemysław Staniszewski Here's a answer.

How to solve combined one-to-one and one-to-many relationship in EF 5 Code First

巧了我就是萌 提交于 2019-12-03 20:51:53
I´m using Entity Framework 5 and Code First. I have two domain entities Question and Answer for a quiz application. One question has several possible answers. A question also has one correct answer which should reference one of the possible answers. I am experiencing some issues with the combination of a one-to-many and one-to-one relationship between the to entities. See Q1 and Q2 . This is the code for the entities: public class Question { public virtual int Id { get; set; } [Required] public virtual string Text { get; set; } [InverseProperty("Question")] public virtual ICollection<Answer>

Entity Framework Migrations renaming tables and columns

一世执手 提交于 2019-12-03 17:55:37
问题 I renamed a a couple entities and their navigation properties and generated a new Migration in EF 5. As is usual with renames in EF migrations, by default it was going to drop objects and recreate them. That isn't what I wanted so I pretty much had to build the migration file from scratch. public override void Up() { DropForeignKey("dbo.ReportSectionGroups", "Report_Id", "dbo.Reports"); DropForeignKey("dbo.ReportSections", "Group_Id", "dbo.ReportSectionGroups"); DropForeignKey("dbo.Editables"

Code-first: Mapping entities to existing database tables

时光总嘲笑我的痴心妄想 提交于 2019-12-03 17:07:31
问题 I am using Entity Framework 6 code-first with an existing database, but having problems mapping my entities to the database tables. Normally, I would use database-first approach and have my entity and context code generated, but using the designer has become a huge pain. I have set Database.SetInitializer(null) as I do not want EF to change my schema. Database schema: Code-first: public class Project { public int ProjectId { get; set; } public string Name { get; set; } public string

EF 5.0 Enums Not Generating

拟墨画扇 提交于 2019-12-03 16:55:46
BACKGROUND I'm using VS 2010 on a machine where I installed .Net 4.5 which I've read was an in-place install (overrode the .net 4.0 version). I have projects still targeting 4.0 and 4.5 option is not available but was told it's ok since 4.5 was an in-place install. I then installed EntityFramework -pre via nuget and notices when I ran Upgrade-Database -Script commands, it would not generate enum properties. I then found this . I tried doing everything from scratch again but it was still adding EntityFramework 4.4 instead of 5.0. So I manually changed all references to point to the 5.0 version

Entity Framework Code-First Migrations - Cannot drop constraint because it doesn't exist (naming convention from 4.3 to 5.0)

有些话、适合烂在心里 提交于 2019-12-03 16:54:06
问题 Was previously using EF 4.3 and upon upgrading to 5.0 I find out the Indexes, FK constraints, and PK constraints all have had their naming conventions changed to include dbo (eg. PK_Users has now become PK_dbo.Users) Now anytime I make a change to the model and it needs to change a table that has these in it, it always says it can't drop constraint because it can't find it. I just want it so that when it tries to drop a constraint/index/key it first checks to see if the pre-5.0 naming one

EF5 code first with ASP.NET Web API: Update entity with many-to-many relationship

*爱你&永不变心* 提交于 2019-12-03 16:07:57
I'm trying to update a Customer in my database using ASP.NET Web API and Entity Framework 5 code-first, but it's not working. My entities look like this: public class CustomerModel { public int Id { get; set; } public string Name { get; set; } // More fields public ICollection<CustomerTypeModel> CustomerTypes { get; set; } } public class CustomerTypeModel { public int Id { get; set; } public string Type { get; set; } [JsonIgnore] public ICollection<CustomerModel> Customers { get; set; } } Nothing all that special. I've built a web interface where users can add a customer by supplying the name

“Cloning” EntityConnections and ObjectContexts in Entity Framework

为君一笑 提交于 2019-12-03 15:29:29
(This used to be a 2-part question, but since the second part is literally the important one, I decided to split this into two separate posts. See Using Serialization to copy entities between two ObjectContexts in Entity Framework for the second part. I want to create a fairly generic "cloner" of databases for my entity model. Also, I might need to support different providers and such. I'm using ObjectContext API. I am aware of this question already and the EntityConnectionStringBuilder MDSN documentation example, but I need to know if there is a programmatic way to obtain the values to