entity-framework-core

How to call ThenInclude twice in EF Core?

蹲街弑〆低调 提交于 2020-01-01 07:55:09
问题 I'm creating an ASP.NET Core API app, and relying on EF Core. I have entities defined like this: public class AppUser : IdentityUser { public string FirstName { get; set; } public string LastName { get; set; } [InverseProperty(nameof(Post.Author))] public ICollection<Post> Posts { get; set; } = new List<Post>(); } public class Post { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } public string AuthorId { get; set; } [ForeignKey("AuthorId")] public

Include all navigation properties using Reflection in generic repository using EF Core

大城市里の小女人 提交于 2020-01-01 04:55:13
问题 I'm working on creating a generic repository for an EF Core project to avoid having to write CRUD for all models. A major roadblock I've hit is navigation properties not being loaded since Core doesn't yet support lazy loading and the generic class obviously can't define .Include statements for class specific properties. I'm trying to do something like this for my Get method to include all the properties dynamically: public virtual T Get(Guid itemId, bool eager = false) { IQueryable<T>

Entity Framework core - Contains is case sensitive or case insensitive?

怎甘沉沦 提交于 2020-01-01 04:24:05
问题 "Contains" in Entity Framework core should equivalent to the SQL %like% operator. Therefore "Contains" should be case insensitive however it is case sensitive! (at least in postgres????) The following only outputs a result when the correct casing for keyword is used. context.Counties.Where(x => x.Name.Contains(keyword)).ToList(); What am I doing wrong? 回答1: It used to be the case for older versions of EF core. Now string.Contains is case sensitive, and for exemple for sqlite it maps to sqlite

Is there a way to run EF Core RC2 tools from published DLL?

本秂侑毒 提交于 2020-01-01 04:19:17
问题 After publishing a .Net Core RC1 application, commands specified in the project.json had corresponding .cmd files created for them which could be executed after deployment (e.g. web.cmd and ef.cmd). In my case, I want to run the following Entity Framework command on my deployment target: dotnet ef database update -c MyContext This works fine when I run this from the folder containing the source code, however after publishing, it doesn't appear to find the command within the compiled DLLs. My

Startup/first query extremely slow

吃可爱长大的小学妹 提交于 2020-01-01 03:49:24
问题 It takes a while (3 minutes+) to 'create/compile' my DbContext. The web server starts in about 5 seconds, but when I do the first query to my database, EF 2.0 has to 'build/create/compile' the database in memory or something, I think? The next requests are almost instant. This was a Database First creation of the DbContext, the database already exists in MSSQL and has data. The DbContext contains about 500 DbSet's with relations. Is there a way to speed this up by doing the 'creation(mapping?

Entity Framework 7 audit log

戏子无情 提交于 2020-01-01 03:32:05
问题 I am porting an old project over to ASP.NET 5 and Entity Framework 7. I have used the database first approach (DNX scaffold) to create the model. The old project is based on Entity Framework 4 and audit tracking is implemented by overriding the SaveChanges method of the DbContext : public override int SaveChanges(System.Data.Objects.SaveOptions options) { int? UserId = null; if (System.Web.HttpContext.Current != null) UserId = (from user in Users.Where(u => u.UserName == System.Web

NoSQL with Entity Framework Core [closed]

戏子无情 提交于 2019-12-31 21:24:31
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 9 months ago . I need any NoSQL provider for Entity Framework Core. Can I use the EF-Core version with MongoDB /Raven or anything? 回答1: Support for NoSQL database providers such as Azure Table Storage, Redis and others (like MongoDb) are still in EF Core team backlog and has not been implemented yet and will not be

Entity framework Core Update-database specific migration

大城市里の小女人 提交于 2019-12-31 17:39:15
问题 I am trying to figure out how to run a specific migration from the package manager in nuget. I have tried to run: update-database -TargetMigration test32 But I do get this message: A parameter cannot be found that matches parameter name 'TargetMigration'. I read about that command from Microsoft's documentation to a previous ef version. So I am not sure how it is in ef core. 回答1: According to EF Core Docs, correct parameter name is -Target (for EF Core 1.1) or -Migration (for EF Core 2.0) so

Entity framework Core Update-database specific migration

做~自己de王妃 提交于 2019-12-31 17:38:23
问题 I am trying to figure out how to run a specific migration from the package manager in nuget. I have tried to run: update-database -TargetMigration test32 But I do get this message: A parameter cannot be found that matches parameter name 'TargetMigration'. I read about that command from Microsoft's documentation to a previous ef version. So I am not sure how it is in ef core. 回答1: According to EF Core Docs, correct parameter name is -Target (for EF Core 1.1) or -Migration (for EF Core 2.0) so

Which one must I use, MyDbContext.Blogs.Add(ablog) or MyDbContext.Add(ablog)?

♀尐吖头ヾ 提交于 2019-12-31 04:23:06
问题 Consider I have a context MyDbContext inherits DbContext of EFCore 2.0. Blogs is a DbSet<Blog> and Blog is an entity model. When I add a new Blog instance, ablog to the Blogs , which one must I use? MyDbContext.Add(ablog); or MyDbContext.Blogs.Add(ablog); ? How about Find ? MyDbContext.Find<Blog>(1); or MyDbContext.Blogs.Find(1); ? Is there any benefit to use one over the other one? 回答1: Adding directly data via the DbContext is new to the DbContext in Entity Framework Core and have no