entity-framework-core

Can I inject dependency into migration (using EF-Core code-first migrations)?

强颜欢笑 提交于 2021-02-07 05:12:13
问题 I tried to inject IConfiguration into the migration (in constructor), and got exception: "No parameterless constructor defined for this object." any workaround? 回答1: you cannot, the migrations need to be able to run outside the context of your application. Since the Entity-framework command-line tool analyzes your code but does not run the startup.cs class. Also it is not advisable. your migrations should be plain simple and not depend on anything. if it would, it could lead to major runtime

Can I inject dependency into migration (using EF-Core code-first migrations)?

偶尔善良 提交于 2021-02-07 05:06:43
问题 I tried to inject IConfiguration into the migration (in constructor), and got exception: "No parameterless constructor defined for this object." any workaround? 回答1: you cannot, the migrations need to be able to run outside the context of your application. Since the Entity-framework command-line tool analyzes your code but does not run the startup.cs class. Also it is not advisable. your migrations should be plain simple and not depend on anything. if it would, it could lead to major runtime

EF Core Collection Load .. of a Collection

℡╲_俬逩灬. 提交于 2021-02-06 10:49:42
问题 Using EF Core 1.1.0 I have a model that has collections that themselves have collections. public class A { public string Ay {get;set;} public List<B> Bees {get;set;} } public class B { public string Be {get;set;} public List<C> Seas {get;set;} } public class C { public string See {get;set;} public bool InDark {get;set;} public List<D> Sigh {get;set;} } Now.. A is huge, and 99% of the time I don't care about B, so it doesn't get loaded. If I did load it, then it would be something like:

EF Core Collection Load .. of a Collection

纵然是瞬间 提交于 2021-02-06 10:46:29
问题 Using EF Core 1.1.0 I have a model that has collections that themselves have collections. public class A { public string Ay {get;set;} public List<B> Bees {get;set;} } public class B { public string Be {get;set;} public List<C> Seas {get;set;} } public class C { public string See {get;set;} public bool InDark {get;set;} public List<D> Sigh {get;set;} } Now.. A is huge, and 99% of the time I don't care about B, so it doesn't get loaded. If I did load it, then it would be something like:

EF Core Collection Load .. of a Collection

你。 提交于 2021-02-06 10:46:07
问题 Using EF Core 1.1.0 I have a model that has collections that themselves have collections. public class A { public string Ay {get;set;} public List<B> Bees {get;set;} } public class B { public string Be {get;set;} public List<C> Seas {get;set;} } public class C { public string See {get;set;} public bool InDark {get;set;} public List<D> Sigh {get;set;} } Now.. A is huge, and 99% of the time I don't care about B, so it doesn't get loaded. If I did load it, then it would be something like:

EF Core 3 - Using an extension method of string inside Where clause

蹲街弑〆低调 提交于 2021-02-05 12:09:35
问题 I have a simple extension method for strings: public static class FrenchStringExtensions { public static string ReplaceAccents(this string str) { return str .Replace("ç", "c") .Replace("é", "e") .Replace("ê", "e") .Replace("è", "e") .Replace("ë", "e") .Replace("â", "a") .Replace("à", "a") .Replace("î", "i") .Replace("ï", "i") .Replace("ô", "o") .Replace("û", "u") .Replace("ù", "u") .Replace("ü", "u"); } } When I try to call this method inside Where() clause like this: var supportTeamsQuery =

NullReferenceException in EF Core when using StringComparison overload for predicates

戏子无情 提交于 2021-02-05 11:46:53
问题 We are converting a project from using EF to using EF Core. We have the following line of code which used to work but now does not: // throws NullReferenceException var u = db.Users.FirstOrDefault(x => x.PresenterID.Equals(uid, StringComparison.OrdinalIgnoreCase)); However, if we don't use the StringComparison overload, it works: // this works var u = db.Users.FirstOrDefault(x => x.PresenterID.Equals(uid)); This is a large project and we would like to avoid finding and modifying all code that

Error while using CosmosDB provider for Entity Framework Core with Azure Tables

99封情书 提交于 2021-02-05 11:42:43
问题 I'm trying to do a simple CRUD application with EF Core and Azure Table (from Azure Storage Account). I'm passing name of the storage account as database name (The docs aren't exactly clear on that) services.AddDbContext<HomioDbContext>(options => options.UseCosmos( "https://homiostorage.table.core.windows.net/", "{Account Key}", databaseName: "{name of storage account}")); Doing any db operation throws following error ( The value for one of the HTTP headers is not in the correct format )

Avoid or control circular references in Entity Framework Core

限于喜欢 提交于 2021-02-05 11:16:12
问题 I really am done with this, but at least I want to know what's going on. Here we go: My project is an ASP.NET Core Web Application with Code First Entity Framework Core and an Angular frontend. I want to control when to load referenced objects. They can be useful, but they can also create circular references with internal errors on the frontend. (JSON would be infinitely long.) Models: class Book { public virtual ICollection<Page> Pages { get; set; } ...simple properties } class Page { public

Avoid or control circular references in Entity Framework Core

别说谁变了你拦得住时间么 提交于 2021-02-05 11:15:12
问题 I really am done with this, but at least I want to know what's going on. Here we go: My project is an ASP.NET Core Web Application with Code First Entity Framework Core and an Angular frontend. I want to control when to load referenced objects. They can be useful, but they can also create circular references with internal errors on the frontend. (JSON would be infinitely long.) Models: class Book { public virtual ICollection<Page> Pages { get; set; } ...simple properties } class Page { public