entity-framework-core

DbSet.Include operator for ef7 accepting string path

£可爱£侵袭症+ 提交于 2019-12-22 05:07:26
问题 EF6 has an overload of DbSet.Include which accepts a string parameter representing a dot-separated list of related objects to return in the query results. It is useful for eager-loading entities in a multi-level object graph. For example: var order = await _dbContext.Orders .Include(o => o.Customer) .Include("OrderDetails.Product") // dot-delimited path .SingleOrDefaultAsync(o => o.OrderId == id); This will return both related order details and populate the Product property of each detail by

DbSet.Include operator for ef7 accepting string path

柔情痞子 提交于 2019-12-22 05:07:25
问题 EF6 has an overload of DbSet.Include which accepts a string parameter representing a dot-separated list of related objects to return in the query results. It is useful for eager-loading entities in a multi-level object graph. For example: var order = await _dbContext.Orders .Include(o => o.Customer) .Include("OrderDetails.Product") // dot-delimited path .SingleOrDefaultAsync(o => o.OrderId == id); This will return both related order details and populate the Product property of each detail by

Entity Framework 7 Set decimal precision for model builder

女生的网名这么多〃 提交于 2019-12-22 05:01:56
问题 I have been trying to figure out how to set the decimal precision for EF7 (Beta 4) with no luck. I was expecting to do something like: modelBuilder.Entity<SomeClass>().Property(p => p.DecimalProperty).Precision(10, 6) This does not appear to be available, but I was able to find the following class in the repository in GitHub: https://github.com/aspnet/EntityFramework/blob/7.0.0-beta4/src/EntityFramework.Relational/RelationalDecimalTypeMapping.cs There are no examples of using the

IHostingEnvironment.WebRootPath is null when using EF7 commands

谁都会走 提交于 2019-12-22 04:11:12
问题 Problem When I try to add a migration to my code, e.g: dnx ef migrations add initial , the env.WebRootPath in Startup(IHostingEnvironment env) is null. This will give me compilation errors when adding a new migration or updating the database. The Code In the Startup.cs class I have these lines in the constructor: public Startup(IHostingEnvironment env) { // ... MyStaticClass.Initialize(env.WebRootPath); // ... _hostingEnvironment = env; } Here env.WebRootPath is null and in the Initialize

IHostingEnvironment.WebRootPath is null when using EF7 commands

一曲冷凌霜 提交于 2019-12-22 04:11:12
问题 Problem When I try to add a migration to my code, e.g: dnx ef migrations add initial , the env.WebRootPath in Startup(IHostingEnvironment env) is null. This will give me compilation errors when adding a new migration or updating the database. The Code In the Startup.cs class I have these lines in the constructor: public Startup(IHostingEnvironment env) { // ... MyStaticClass.Initialize(env.WebRootPath); // ... _hostingEnvironment = env; } Here env.WebRootPath is null and in the Initialize

many to many EF7

牧云@^-^@ 提交于 2019-12-22 04:09:34
问题 Models: public partial class Film { public int FilmID { get; set; } public virtual ICollection<Genre> Genres { get; set; } } public class Genre { public int GenreID { get; set; } public virtual ICollection<Film> Films { get; set; } } OnModelCreating using EF6 protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<Film>() .HasMany(e => e.Genres) .WithMany(e => e.Films) .Map(m => m.ToTable("Genre_Film").MapLeftKey("Films_IdFilm").MapRightKey("Genres_IdGenre")

Entity Framework Core: private or protected navigation properties

為{幸葍}努か 提交于 2019-12-22 04:07:07
问题 Is it somehow possible to define navigation properties in EFCore with private or protected access level to make this kind of code work: class Model { public int Id { get; set; } virtual protected ICollection<ChildModel> childs { get; set; } } 回答1: You have two options, using type/string inside the model builder. modelBuilder.Entity<Model>(c => c.HasMany(typeof(Model), "childs") .WithOne("parent") .HasForeignKey("elementID"); ); Not 100% sure it works with private properties, but it should.

What logic determines the insert order of Entity Framework 6

女生的网名这么多〃 提交于 2019-12-22 03:24:29
问题 So, I have a DBContext, and I am doing the following operations: dbContext.SomeTables1.Add(object1) dbContext.SomeTables2.AddRange(objectArray2) dbContext.SomeTables3.AddRange(objectArray3) dbContext.SaveChanges(); The EF doesn't insert the db records in this order, it inserts them in a random order. To insert them in the same order, I have to do a dbContext.SaveChanges() after each addition. This is not an efficient solution and in my case, it is taking 10 seconds to do all my inserts, while

How to update a Collection in Many-Many by assigning a new Collection?

Deadly 提交于 2019-12-21 20:53:09
问题 In entity framework core 2.0, I have many-many relationship between Post and Category (the binding class is PostCategory ). When the user updates a Post , the whole Post object (with its PostCategory collection) is being sent to the server, and here I want to reassign the new received Collection PostCategory (the user may change this Collection significantly by adding new categories, and removing some categories). Simplified code I use to update that collection (I just assign completely new

How to run dynamic SQL query in Entity Framework 7 that auto-maps to Entities (SqlQuery<T>)?

柔情痞子 提交于 2019-12-21 20:09:20
问题 I have an existing app that I am trying to upgrade from MVC5/EF6 to MVC6/EF7. We dynamically create some of our SQL tables, and as a result, have made use of the System.Data.Entity.Database.SqlQuery method to automatically map to entities that we use throughout our application. This method seems to have gone away (i.e. not part of Microsoft.Data.Entity.Infrastructure.Database ) in EF7 (or is not yet implemented). Are there plans to re-implement this method in EF7 or is there another way to