entity-framework-core

Cannot access a disposed object exception when method invoked by fluent scheduler job

◇◆丶佛笑我妖孽 提交于 2019-12-25 09:08:04
问题 I'm getting the "Cannot access a disposed object" exception during a call to a method that uses a DI-injected dbcontext (Transient-scoped)-- most likely the dbcontext was already disposed when being invoked. The method is being invoked as a job by fluent scheduler: JobManager.AddJob( () => ExecuteUpdateDbContext(), (s) => s.ToRunNow().AndEvery(60).Minutes() ); The ExecuteUpdateDbContext method works in any under circumstance except when used by fluent scheduler. Do I need to do something

How to build several left join query in Entity Framework Core for several many to one related entities

六月ゝ 毕业季﹏ 提交于 2019-12-25 09:04:10
问题 Defined model and classes protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity<RootLink>() .HasOne(link => link.Node) .WithMany(node => node.RootLinks) .HasForeignKey(link => link.NodeId); modelBuilder.Entity<RootLink>() .HasOne(link => link.RootNode) .WithMany() .HasForeignKey(rootLink => rootLink.RootNodeId) .OnDelete(DeleteBehavior.Restrict); modelBuilder.Entity<NodeLink>() .HasOne(link => link.Node) .WithMany(node =>

Unable to load DLL 'sni.dll' - Entity Framework Core

Deadly 提交于 2019-12-25 08:53:39
问题 When using Entity Framework Core in an ASP.Net Core application on Visual Studio 2017 I intermittently get the error "Unable to load 'sni.dll'. Strangely though I have found a temporary fix: restarting my PC. I don't know why the error keeps happening, I don't know what the variable could be. Could anyone shed light on the possible cause? I would offer a full stack trace but it hasn't happened since deciding to post on here, when it next happens I'll be sure to update this. I know for certain

ConnectionString not read properly - EF Core

五迷三道 提交于 2019-12-25 08:35:34
问题 I'm using EF Core to connect to a MySQL database. Ever since upgrading from 1.0 to 1.1, my connection string does not seem to be read properly. Here is my project.json: { "version": "1.0.0-*", "dependencies": { "MySql.Data": "7.0.6-IR31", "MySql.Data.EntityFrameworkCore": "7.0.6-IR31", "NETStandard.Library": "1.6.1" }, "tools": { "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-*" }, "frameworks": { "netstandard1.6": { "imports": "dnxcore50" } } } I'm initialising a DBContext like this:

GroupBy first result of lookup table in Entity Framework Core

北慕城南 提交于 2019-12-25 08:15:26
问题 I'm trying to get the total Man Days worked by volunteers per section between a date range. There is an attendance table which includes the day and the member id to map to the member table. There is also a section table to list all the sections and a membertosection table as a member can be in more than one section. I want to group by the first section a member is in and then have a count of all the attendance days for that section. The following works perfectly where I'm grouping by a 1 to

EF Core - Connection string cannot be null

冷暖自知 提交于 2019-12-25 03:35:09
问题 I am using ASP.Net Core 2.1 with EF Core 2.1 While running any Migration from PMC, I am getting the below error Value cannot be null. Parameter name: connectionString This is how my Context class looks like public class MyAppContextFactory : IDesignTimeDbContextFactory<MyAppContext> { private readonly string _dbConnection; public MyAppContextFactory() { } public MyAppContextFactory(string dbConnection) : this() { _dbConnection = dbConnection; } public MyAppContext CreateDbContext(string[]

EF Core - Connection string cannot be null

ぐ巨炮叔叔 提交于 2019-12-25 03:35:03
问题 I am using ASP.Net Core 2.1 with EF Core 2.1 While running any Migration from PMC, I am getting the below error Value cannot be null. Parameter name: connectionString This is how my Context class looks like public class MyAppContextFactory : IDesignTimeDbContextFactory<MyAppContext> { private readonly string _dbConnection; public MyAppContextFactory() { } public MyAppContextFactory(string dbConnection) : this() { _dbConnection = dbConnection; } public MyAppContext CreateDbContext(string[]

EF Core navigation property for eager load child parent grandparent

好久不见. 提交于 2019-12-25 01:45:35
问题 I had a table that relates Country, State and County, being county the child, state the parent and country the grandparent. I want to have a employee table with a navigation property that could reference to a child county in region table and be able to eager load related child parent grandparent, I mean Country, State and County. How can I define such relation and eager load?. I had define the models as follows.. public enum RegionTypeEnum { Country = 0, State = 1, County = 2, } public class

Saving entity with owned property

十年热恋 提交于 2019-12-25 01:38:04
问题 Ok, this might be a dumb question, but I can't figure it out (tried searching but with no reasonable effect). I have a model: public class Freelancer { public Address Address { get; set; } public Guid Id { get; set; } } public class Address { public string Name1 { get; set; } public string Name2 { get; set; } public string ZipCode { get; set; } public string City { get; set; } } which is configured as follows: modelBuilder.Entity<Freelancer>().HasKey(x => x.Id); modelBuilder.Entity<Freelancer

Create custom objects from IQueryable without loading everything into memory

馋奶兔 提交于 2019-12-25 01:13:00
问题 This is a follow up question to this question. You should read that first. I have now, thanks to this answer, created a query that will return the correct entries. See: IQueryable<Data> onePerHour = dataLastWeek .Where(d => !dataLastWeek .Any(d2 => d2.ArchiveTime.Date == d.ArchiveTime.Date && d2.ArchiveTime.Hour == d.ArchiveTime.Hour && d2.ArchiveTime < d.ArchiveTime)); Now for processing the entries and displaying them on a chart, I only need one or two properties of the model class Data .