ef-core-2.1

Filtering with EF Core 2.1 inheritance

限于喜欢 提交于 2020-08-05 06:52:54
问题 I'm trying to find a way to filter my results in EF Core 2.1, when using inherited objects. I've got a base model and several inherited classes (but I've just included one): public class Like { public int Id { get; set; } public LikeType LikeType { get; set; } } public class DocumentLike : Like { [ForeignKey(nameof(Document))] public int DocumentId { get; set; } public virtual Document Document { get; set; } } LikeType is an enum which is defined as the discriminator in the dbcontext. Every

EF Core 2.1 - Duplicate relationships when use fluent API

|▌冷眼眸甩不掉的悲伤 提交于 2020-08-03 09:23:08
问题 I develop a web API with .NET Core 2.1 and EF Core. But i have a problem with my ApplicationDbContext that i don't understand. I have 2 tables (Users and Profiles, one to many), the foreign key profile in User table is not required. With Fluent API, when i declare my relationships, ef core create duplicate foreign key on the same reference, but why ? Here is my userModel : public class UserModel { public long Id { get; set; } public string Username { get; set; } public string Password { get;

EF Core 3 x.Contains() in expression where x is ICollection

a 夏天 提交于 2020-07-18 11:03:56
问题 I've got the following data layer setup: public class Repository : IRepository { private readonly MyDbContext _dbContext; public List<Meter> Search(Expression<Func<Meter,bool>> criteria) IQueryable<Meter> results = _dbContext.Meters; return results.Where(criteria).ToList(); } } } ... from a client class: IRepository _repository; public void ClientMethod () { ICollection<int> ids = new List<int>() {1, 2, 3); var results = _repository.Search(c=> ids.Contains(c.Id)); // This throws exception }

Scaffold-DbContext for database views in EF Core 2.1 (Query Types)

戏子无情 提交于 2020-05-11 09:03:07
问题 EF Core 2.1 has new feature - Query Types . Some of the main usage scenarios for query types are: Serving as the return type for ad hoc FromSql() queries. Mapping to database views. Mapping to tables that do not have a primary key defined. Mapping to queries defined in the model. I upgrade project to Core 2.1, but Scaffold-DbContext still does not generate database views. I have to use a special parameter or the Scaffold-DbContext does not support it? 回答1: Not supported in 2.1. See issue

The property X is of type Y which is not supported by current database provider

∥☆過路亽.° 提交于 2020-03-21 11:27:10
问题 I am really new to EF (using EF core 2.1) and have been following a bunch of tutorials so far, but now I have ventred in to creating my own DB structure and stumbled when trying to add a value in to the DB: private async Task<int> Insert() { var address = new Address { AddressLine1 = "1 any street", AddressLine2 = "", AddressLine3 = "", City = "Any city" }; using (var context = new BranchContext()) { context.Addresses.AddAsync(address);//ERROR HERE .... } } I get the error: