ef-code-first

Complex type: multiple instances in one model?

岁酱吖の 提交于 2019-12-23 08:49:07
问题 Is there a way to have multiple instances of complex type inside the same model using Fluent api model builder? public class Contact { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public Address PersonalAddress { get; set; } public Address BusinessAddress { get; set; } } public class Address { public string Street{ get; set; } public string City{ get; set; } public string PostalCode{ get; set; } } protected override void

EF Code First forced eager loading

谁说我不能喝 提交于 2019-12-23 07:49:18
问题 I'm using EF 5 with Code First. I have a class that I want to always eager load some properties. I removed the virtual keyword but it's not eager loading: public class Person { public ICollection<Email> Emails { get; set; } public Profile Profile {get;set;} } So by turning off lazy loading, it won't auto eager load right? If so, how do I archive that without using Include()? Thanks! 回答1: No, turning off lazy loading by removing the virtual keyword will not automatically enable eager loading.

How to change/set collation in EF Code first

老子叫甜甜 提交于 2019-12-23 07:38:25
问题 I want to change Collation of the whole database created by ef code first, I try to do it by running a script after creation but it does not works, _dbContext.Database.Delete(); _dbContext.Database.CreateIfNotExists(); _dbContext.Database.ExecuteSqlCommand("ALTER DATABASE afi COLLATE French_CI_AI"); Is it possible to set the collation before creating the database? That is the exception I get : Resetting the connection results in a different state than the initial login. The login fails. Login

Entity Framework Table Splitting: not in the same type hierarchy / do not have a valid one to one foreign key relationship

江枫思渺然 提交于 2019-12-23 06:57:03
问题 I'm using Entity Framework 6 with a Code-First approach, and I want two entities to be put in the same table. What am I doing wrong? [Table("Review")] public class Review { public int Id { get; set; } public PictureInfo PictureInfo { get; set; } public int PictureInfoId { get; set; } } [Table("Review")] public class PictureInfo { [Key, ForeignKey("Review")] public int ReviewId { get; set; } public Review Review { get; set; } } The error I get: The entity types 'PictureInfo' and 'Review'

Code First - UML - Modeling of database - visual view possible?

依然范特西╮ 提交于 2019-12-23 06:04:11
问题 I love how model first gives a visual overview of the database. But now the Ado.Net team pushes code first, i'd think it would be awesome to generate an UML overview of the database through your classes. Does this already exists? As i can't seem to find it :( 回答1: Yes it exists as part of EF Power Tools CTP1 where you can generate read-only EDMX from your code first mapping. It is not UML but it is the same diagram you had with model first. 回答2: UML is representing an object approach while

update-database fires: “There is already an object named 'Adresses' in the database”.

我是研究僧i 提交于 2019-12-23 05:44:08
问题 I can't get my seed method to run on an alredy existing database. The database was a result of multiple migrations where we migrated our own created database, "Whitelabel", with the ASP.NET MVC5 Identity database (that we call "IdentityDb"). Here's an overview of the database tables: Since this is made code-first, I used the package manager console to update the database with this command: PM> update-database -ConfigurationTypeName DAL.DataContexts.WhitelabelMigrations.Configuration And it

Entity Framework Code First Set Foreign Key Name

孤人 提交于 2019-12-23 05:03:35
问题 I have two tables: User ID Email Task Email TaskName The user can have multiple tasks. I need to specify that Email is the foreign key relationship between my task and email table. How can this be done? Here is my code: public MyDataContext() : base("Default") { } public DbSet<User> Users { get; set; } public DbSet<Task> Tasks { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<User>() .ToTable("User").HasRequired(m => m.Tasks) .WithMany()

EF 6 Code First __MigrationHistory in dbo schema by default

对着背影说爱祢 提交于 2019-12-23 04:10:26
问题 I am new to Code first Entity framework, when logging into the database after running my app for the first time I got a little confused when I saw the "__MigrationHistory" table. I now understand the need for this table, but do not like it being in the standard dbo schema within the user table, I think its obtrusive and a risk. My first thought was to move it to the system folder. When researching how to achieve this within the EF context all I could find is how to move it from system to dbo.

How to UPDATE DATABASE in Code First approach automatically after check-in and Publish code in Continuous deployment

会有一股神秘感。 提交于 2019-12-23 03:19:57
问题 ​In our Web API application, Continuous deployment need a following scenario. User will check in code in VS, Code will get automatically build, Code will be Published, Code will be deployed. But If we are using Entity Framework Code First approach, How can we update database without manual commands (Add-Migration/Update Database)and make database up to date with that check-in. 回答1: You can try to run Add-Migration/Update Database commands in the build/deploy process. Assume you are using

ASP.NET MVC Entity Framework CodeFirst Many To Many (CRUD)

流过昼夜 提交于 2019-12-23 03:18:32
问题 I have a few problems but I'm going to start with the first and smallest. I have two models with a many-many relationship, Category and Project. In each model I have an ICollection of the other model. I initialize the collection as a new HashSet() for the Project constructor and vice-versa for the Category. I've read online that this will create a new table in your database with the PK of each model as the PK in the new table. I custom named them and whatnot through Fluent API but you get the