entity-framework-core

Entity Framework 3.0 Contains cannot be translated in SQL as it was in EF Core 2.2

被刻印的时光 ゝ 提交于 2020-04-10 14:03:18
问题 I am trying to migrate a Web API from .NET Core 2.2 to .NET Core 3.0 and I have stumbled across the following: public Dictionary<int, Tag> GetTagMap(IList<int> tagIds = null) { var tags = context.Tag.AsNoTracking(); if (tagIds != null) tags = tags.Where(t => tagIds.Contains(t.TagId)); return tags .ToList() // explicit client evaluation in 3.0 .ToDictionary(t => t.TagId, t => t); } This used to generate a SQL statement similar to this one: SELECT TagId, Name FROM Tag WHERE TagId IN (1, 2, 3)

Entity Framework 3.0 Contains cannot be translated in SQL as it was in EF Core 2.2

半腔热情 提交于 2020-04-10 14:02:06
问题 I am trying to migrate a Web API from .NET Core 2.2 to .NET Core 3.0 and I have stumbled across the following: public Dictionary<int, Tag> GetTagMap(IList<int> tagIds = null) { var tags = context.Tag.AsNoTracking(); if (tagIds != null) tags = tags.Where(t => tagIds.Contains(t.TagId)); return tags .ToList() // explicit client evaluation in 3.0 .ToDictionary(t => t.TagId, t => t); } This used to generate a SQL statement similar to this one: SELECT TagId, Name FROM Tag WHERE TagId IN (1, 2, 3)

Scaffold-DbContext to different output folder

痞子三分冷 提交于 2020-04-10 08:24:48
问题 I'm implementing repository pattern in company solution I work for, separating model classes in a Backend project and database context and migrations in DbContexts project. I'm using Scaffold-DbContext setting my Backend Project as default project to destination of model classes, however DbContext Class is always created in same folder as model classes. Is it possible to redirect the creation of the DbContext class to a different output folder, in my case to DbContexts project? 回答1: It is now

BeginTransaction with IsolationLevel in EF Core

半城伤御伤魂 提交于 2020-04-09 18:41:12
问题 I'm trying to rewrite old library to use EntityFramework Core and I can't figure out how to begin transaction with specific isolation level. Previously I was able to do something like this: DbContext.Database.BeginTransaction(IsolationLevel.Snapshot); What is alternative implementation in the EntityFramework Core? 回答1: The EF Core code is exactly the same. DbContext.Database.BeginTransaction(IsolationLevel.Snapshot); The only difference is that in EF Core the method with isolation level (as

BeginTransaction with IsolationLevel in EF Core

我怕爱的太早我们不能终老 提交于 2020-04-09 18:41:11
问题 I'm trying to rewrite old library to use EntityFramework Core and I can't figure out how to begin transaction with specific isolation level. Previously I was able to do something like this: DbContext.Database.BeginTransaction(IsolationLevel.Snapshot); What is alternative implementation in the EntityFramework Core? 回答1: The EF Core code is exactly the same. DbContext.Database.BeginTransaction(IsolationLevel.Snapshot); The only difference is that in EF Core the method with isolation level (as

Entity Framework circular dependency for last entity

坚强是说给别人听的谎言 提交于 2020-04-08 09:22:05
问题 Please consider the following entities public class What { public int Id { get; set; } public string Name { get; set; } public ICollection<Track> Tracks { get; set; } public int? LastTrackId { get; set; }] public Track LastTrack { get; set; } } public class Track { public Track(string what, DateTime dt, TrackThatGeoposition pos) { What = new What { Name = what, LastTrack = this }; } public int Id { get; set; } public int WhatId { get; set; } public What What { get; set; } } I use the

Use IEntityTypeConfiguration with a base entity

╄→гoц情女王★ 提交于 2020-04-07 19:07:50
问题 In EF Core 2.0, we have the ability to derive from IEntityTypeConfiguration for cleaner Fluent API mappings (source). How can I extend this pattern to utilize a base entity? In the example below, how can I have a BaseEntityConfiguration to reduce duplication in LanguageConfiguration and MaintainerConfiguration , modifying properties that are in the BaseEntity only in the BaseEntityConfiguration ? What would such a BaseEntityConfiguration look like; and how would it be used, if at all, in

Use IEntityTypeConfiguration with a base entity

廉价感情. 提交于 2020-04-07 19:07:49
问题 In EF Core 2.0, we have the ability to derive from IEntityTypeConfiguration for cleaner Fluent API mappings (source). How can I extend this pattern to utilize a base entity? In the example below, how can I have a BaseEntityConfiguration to reduce duplication in LanguageConfiguration and MaintainerConfiguration , modifying properties that are in the BaseEntity only in the BaseEntityConfiguration ? What would such a BaseEntityConfiguration look like; and how would it be used, if at all, in

.Net core 3.x Keyless Entity Types avoid table creation

夙愿已清 提交于 2020-04-07 05:11:32
问题 I need to execute a complex sql query in entity framework core 3.1.1, on researching i found out that keyless entity types is the way to go in code first approach. I see lot of documents for dbquery but this is marked as obsolete in .net core 3.x keyless entity types As per Microsoft documentation it says dbquery is obsolete so use dbset approach instead, but with dbset it is trying to create a new table in database. how to disable table generation in keyless entity types while applying

Converting EF Core queries from 2.2 to 3.0 - async await

女生的网名这么多〃 提交于 2020-04-07 04:01:04
问题 In EF Core 2.2 I had: var data = await _ArticleTranslationRepository.DbSet .Include(arttrans => arttrans.Article) .ThenInclude(art => art.Category) .Where(trans => trans.Article != null && trans.Article.Category != null && trans.Article.Category.Id == categoryId.Value) .GroupBy(trans => trans.ArticleId) .Select(g => new { ArticleId = g.Key, TransInPreferredLang = g.OrderByDescending(trans => trans.LanguageId == lang).ThenByDescending(trans => trans.LanguageId == defaultSiteLanguage).ThenBy