ef-code-first

One to One Relationship on Primary Key with Entity Framework Code First

折月煮酒 提交于 2019-12-31 02:31:10
问题 I'm currently getting the following error when trying to create an one to one relationship using Code First: System.Data.Edm.EdmAssociationEnd: : Multiplicity is not valid in Role 'C001_Holding_Teste_C001_Holding_Source' in relationship 'C001_Holding_Teste_C001_Holding'. Because the Dependent Role refers to the key properties, the upper bound of the multiplicity of the Dependent Role must be 1. My entity definitions are the following: [Table("C001_Holding", Schema = "Cad")] public partial

Entity Framework - Fluent APi - Create table with 2 FK

别来无恙 提交于 2019-12-30 14:09:34
问题 I have this product class which has a list of products associated. eg: Product = StarWar AssociatedProducts = Episode V: The Empire Strikes Back, Episode VI: Return of the Jedi, Episode VII: The Force Awakens But EF generates the database with some extra columns. This is my Product Class: public class Product { public int Id { get; set; } public string Name { get; set; } public string ShortDescription { get; set; } public string FullDescription { get; set; } public decimal UnitPrice { get;

EF, Code First, how to initialize database on a specific location (HDD)

只愿长相守 提交于 2019-12-30 11:09:05
问题 does anybody know how to spedify exact .mdf/.log file location during EF CodeFirst database initialization? For a debug and testing scenario (but specifying exact DB files location can be useful in production as well), I'd like to re-deploy database during application start-up, but also I'd like to create DB files on a specific location (e.g. secong hard drive). public class MyCustomInitialized : DropCreateDatabaseAlways<MyContext> { public override void InitializeDatabase(MyContext context)

EF, Code First, how to initialize database on a specific location (HDD)

◇◆丶佛笑我妖孽 提交于 2019-12-30 11:09:04
问题 does anybody know how to spedify exact .mdf/.log file location during EF CodeFirst database initialization? For a debug and testing scenario (but specifying exact DB files location can be useful in production as well), I'd like to re-deploy database during application start-up, but also I'd like to create DB files on a specific location (e.g. secong hard drive). public class MyCustomInitialized : DropCreateDatabaseAlways<MyContext> { public override void InitializeDatabase(MyContext context)

Loading related entities in separate queries and sorting of children collection

时光总嘲笑我的痴心妄想 提交于 2019-12-30 11:08:28
问题 I need to retrieve data using EF 4.1 Code first that are contained in several related tables. Currently if i use this return Context.Set<Entity>() .Include(x => x.Children.Select(y => y.GrandChildren.Select(z => z.Child))) .Include(x => x.SomeEntity) .Include(x => x.AnotherEntity) .OrderByDescending(x => x.Id) .FirstOrDefault(); The data is fetched correctly, but I am worried about two things: 1) it seems that there is no way to sort Chilren / GrandChildren 2) the data is flattened in one

Accessing Navigation Properties from IdentityUser when LazyLoading is off

我的未来我决定 提交于 2019-12-30 09:29:15
问题 I've this setup with code first model: public class TestContext :IdentityDbContext<TestUser> { public TestContext() : base("TestConnection") { this.Configuration.LazyLoadingEnabled = false; } public DbSet<Customer> Customers{get;set;} } public class TestUser : IdentityUser { public virtual Customer Customer { get; set; } } public class Customer { public int Id { get; set; } public string FirstName { get; set; } public string LastName {get; set;} } I've extended the IdentityUser to contain an

ASP.NET Identity 2.1 and EF 6 - ApplicationUser relationships with other entities

人盡茶涼 提交于 2019-12-30 07:25:42
问题 Can't seem to find an answer to this one, even though what I'm doing seems like it would be common and important to most developers. In most systems with user accounts, the user table is tied to other tables in the database. That's all I want. I'm using MSSQL Express 2012 and VS 2013. I have a class library where I'm using the code-first approach to generate tables. I moved the IdentityModel class from the MVC project to this class library as well. Everything works separately - my tables are

ASP.NET Identity 2.1 and EF 6 - ApplicationUser relationships with other entities

妖精的绣舞 提交于 2019-12-30 07:25:10
问题 Can't seem to find an answer to this one, even though what I'm doing seems like it would be common and important to most developers. In most systems with user accounts, the user table is tied to other tables in the database. That's all I want. I'm using MSSQL Express 2012 and VS 2013. I have a class library where I'm using the code-first approach to generate tables. I moved the IdentityModel class from the MVC project to this class library as well. Everything works separately - my tables are

MaxLength Attribute in EF4.3.1

有些话、适合烂在心里 提交于 2019-12-30 06:09:24
问题 The type 'System.ComponentModel.DataAnnotations.MaxLengthAttribute' exists in both [path...]\packages\EntityFramework.4.3.1\lib\net40\EntityFramework.dll and 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework \.NETFramework\v4.5\System.ComponentModel.DataAnnotations.dll' Now, I have read on msdn that its safe to exclude the EntityFramework reference (which was added through the nuget package). However, when I do that, I cant create a DBContext properly as the DbModelBuilder

How to switch between DatabaseGeneratedOption.Identity, Computed and None at runtime without having to generate empty DbMigrations

自闭症网瘾萝莉.ら 提交于 2019-12-30 04:40:12
问题 I am migrating a legacy database to a new database which we need to access and "manage" (as oxymoronic as it might sound) primarily through Entity Framework Code-First. We are using MS SQL Server 2014. The legacy database contained some tables with computed columns. Typical GUID and DateTime stuff. Technically speaking, these columns did not have a computed column specification, but rather where given a default value with NEWID() and GETDATE() We all know that it is very easy to configure the