ef-code-first

EF Code First Migrations creating extra foreign key

北战南征 提交于 2019-12-10 19:50:29
问题 I'm trying to create a Profile table to integrate with the Asp.Net Identity table: AspNetUsers . I'm using Code First Migrations with EF 6.0. Here is my User class: public class ApplicationUser : IdentityUser { public ApplicationUser() { } public virtual string FirstName { get; set; } public virtual string LastName { get; set; } public UserStatus Status { get; set; } public virtual Profile Profile { get; set; } } Here is my Profile class: public class Profile { public int ID { get; set; }

Should I map both sides of bidirectional relations in EF code first?

若如初见. 提交于 2019-12-10 19:03:20
问题 Assume I have the following entity classes: public class Customer { public int Id { get; set; } public virtual ICollection<Order> Orders { get; set; } } public class Order { public int Id { get; set; } public virtual Customer Customer { get; set; } } How should those be mapped in Entity Framework 6 fluent code-first mapping? I want to be explicit about the mapping and not rely on automatic mapping conventions. Option 1 Just map the local properties of both classes. That's how I would do it in

In EF Code First is there a data annotation for description field?

此生再无相见时 提交于 2019-12-10 18:56:19
问题 While designing a table in MS-SQL you have a choice to add a description for each column you add to the table. Is it possible in EF Code First to do same with help of Data Annotations ? 回答1: Before you are using my soultion please read a little bit about: Extended Properties: https://technet.microsoft.com/en-us/library/ms190243(v=sql.105).aspx Attributes: http://www.dotnetperls.com/attribute My solution will allow you to do a shadow description for any property like that: [Description("My

Error Remapping EF Code First TPH Discriminator

混江龙づ霸主 提交于 2019-12-10 18:36:53
问题 I'm attempting to remap the descriminator column of my TPH-persisted object hierarchy as described at: http://msdn.microsoft.com/en-us/library/hh295845(v=vs.103).aspx http://blogs.msdn.com/b/adonet/archive/2010/12/14/ef-feature-ctp5-fluent-api-samples.aspx https://stackoverflow.com/a/6650064/141172 When I map using either of the following variants: modelBuilder.Entity<MyBase>() .Map<MyBase>(m => m.Requires("TypeId").HasValue(0)) .Map<DerivedA>(m => m.Requires("TypeId").HasValue(1)) .Map

Code-First change data source without connection string

◇◆丶佛笑我妖孽 提交于 2019-12-10 18:31:35
问题 I seem to have an issue creating an MVC4 application where I have adopted the code-first approach to creating my models but no connection string seems to have been created in the web.config file. The constructed database seems to have been built on (localhost)\SQLEXPRESS instance but I would like to change this to an external data source. Without a connection string to update I'm not sure how to do this. Please could someone point me in the right direction? EDIT: I found the following diagram

EF Code First and Database Views

那年仲夏 提交于 2019-12-10 18:17:42
问题 I just started looking at Database Views with Code First... and try to decide if I should use them. Here Ladislav recommends to use NotMapped inheritance parent for table and Db-View (my view only adds sums of child entities)... but how this work with CF Migrations? I really want to use them. Also... navigation properties will work on Db-View Entity? Is there any way to save data directly into Db-View entity (and it's table)? 回答1: If you want to use code first and migrations you should not

Sql Azure - maxing DTU Percentage querying a 'empty table'

早过忘川 提交于 2019-12-10 18:16:58
问题 I have been having trouble with a database for the last month or so... (it was fine in November). (S0 Standard tier - not even the lowest tier.) - Fixed in update 5 Select statements are causing my database to throttle (timeout even). To makes sure it wasn't just a problem with my database, Ive: Copied the database... same problem on both (unless increasing the tier size). Deleted the database, and created the database again (blank database) from entity framework code-first The second one

Entity Framework - Reverse Engineer Code First - Overwriting Changes

梦想与她 提交于 2019-12-10 17:57:57
问题 Im using the EF Power Tools to Reverse Engineer an existing Database. This is fine. Under the EDMX Database-1st Route I would create partial classes for any overrides like Data Annotations, for e.g. here, LedgerPeriod being the original EntityObject: [MetadataType(typeof(LedgerPeriodMetaData))] public partial class LedgerPeriod { public class LedgerPeriodMetaData { [Required(ErrorMessage = "Period Start Date Required")] [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM

Migrate database-first to code-first - switch from publish to migrations

≯℡__Kan透↙ 提交于 2019-12-10 17:57:24
问题 We need to migrate an existing project from database-first to code-first. Each environment (DEV, TEST, PROD) has a slightly different version of the database. The differences are the changes in DEV that may not have been pushed to TEST and PROD. -- We are using Entity Framework 6.1.3. We have a database project that deploys the database. The publish operation compares the database with the project and builds a script to change the database as needed. We have a models project with an edmx

New embedded Firebird, code first, EF6 project results in SerializationException

烈酒焚心 提交于 2019-12-10 17:39:24
问题 I'm trying to set up Firebird with EF6 as an embedded server for a simple app I'm writing but haven't been able to get it to work. I have a CLI project which is the app and the DAL project which is the DB. I added the NuGet packages to both and created a DbContext with a simple entity, and created an initial migration successfully, but when trying to run update-database to execute the migration I received this error in the Package Manager Console: System.Runtime.Serialization