ef-core-3.0

EF Core 3.0 translating string.Equals ordinalIgnoreCase correctly

邮差的信 提交于 2020-12-01 11:07:40
问题 Before EF Core 3.0 this worked fine (evaluated on server+client): var exists = await _context.Countries.AsNoTracking().AnyAsync(x => x.CountryCode.Equals(country.CountryCode, StringComparison.OrdinalIgnoreCase)); What is the best/preferred method to translate the string.Equals(str, StringComparison.OrdinalIgnoreCase) -part now in EF Core 3.0, so that the query evaluates only on the server side. var exists = await _context.Countries.AsNoTracking().AnyAsync(x => x.CountryCode.ToUpper() ==

Load child entity on the fetch of the Parent entity EFCore

筅森魡賤 提交于 2020-11-29 09:39:11
问题 I have the below model. What is the better way to load the parent entity with child entity at the time of fetching from the DB with find method? Parent Entity: public class Client { public int Id { get; set; } public string LastName { get; set; } public string Gender { get; set; } public DateTime DateOfBirth { get; set; } public Address Address { get; set; } } Child Entity: public class Address { public int Id { get; set; } public string FirstLine { get; set; } public string SecondLine { get;

Get Current User in a Blazor component

喜夏-厌秋 提交于 2020-08-02 19:12:34
问题 I'm starting a new site with Blazor and Windows Authentication and need to identify the current user viewing the page/component. For a Razor Page, the current user name can be accessed with Context.User.Identity.Name , but that doesn't seem to work in a Blazor component. I've tried injecting HttpContext into the component but the Context is null at runtime. As a bonus, I will eventually want to incorporate this into Startup.cs so I only need to get the username once and can leverage a

Get Current User in a Blazor component

余生颓废 提交于 2020-08-02 19:01:29
问题 I'm starting a new site with Blazor and Windows Authentication and need to identify the current user viewing the page/component. For a Razor Page, the current user name can be accessed with Context.User.Identity.Name , but that doesn't seem to work in a Blazor component. I've tried injecting HttpContext into the component but the Context is null at runtime. As a bonus, I will eventually want to incorporate this into Startup.cs so I only need to get the username once and can leverage a

How to prevent a column update in EF Core 3.1?

老子叫甜甜 提交于 2020-07-22 03:55:49
问题 I upgraded from .Net Core 2.2 to 3.1 and this functionality has been deprecated modelBuilder .Entity<Order>() .Property(e => e.CreationTime) .ValueGeneratedOnAddOrUpdate() .Metadata.IsStoreGeneratedAlways = true; I need EF to do the Insert but block the update. Thanks! 回答1: According to the obsoleted property implementation: public virtual bool IsStoreGeneratedAlways { get => AfterSaveBehavior == PropertySaveBehavior.Ignore || BeforeSaveBehavior == PropertySaveBehavior.Ignore; set { if (value

How to prevent a column update in EF Core 3.1?

流过昼夜 提交于 2020-07-22 03:55:29
问题 I upgraded from .Net Core 2.2 to 3.1 and this functionality has been deprecated modelBuilder .Entity<Order>() .Property(e => e.CreationTime) .ValueGeneratedOnAddOrUpdate() .Metadata.IsStoreGeneratedAlways = true; I need EF to do the Insert but block the update. Thanks! 回答1: According to the obsoleted property implementation: public virtual bool IsStoreGeneratedAlways { get => AfterSaveBehavior == PropertySaveBehavior.Ignore || BeforeSaveBehavior == PropertySaveBehavior.Ignore; set { if (value

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 }

EF Core 3.1 throws an exception for Contains

柔情痞子 提交于 2020-07-09 12:05:22
问题 I recently updated the project code into .NET Core 3.1 and EF Core 3.1, now most of my linq queries brake, EX. public override ICollection<ContactDetailModel> GetAll(ICollection<int> ids) { return _context .Set<TEntity>() .IgnoreDeletedEntities() .Where(x => ids.Distinct().Contains(x.ContactId)) .Select(EntityToDTOMapper) .ToList(); } This code throws an error where I use Contains, I saw in some other posts this issues has been fixed as a bug, but yet it fails. Error I get is "could not be

EF Core 3.1 throws an exception for Contains

怎甘沉沦 提交于 2020-07-09 12:05:08
问题 I recently updated the project code into .NET Core 3.1 and EF Core 3.1, now most of my linq queries brake, EX. public override ICollection<ContactDetailModel> GetAll(ICollection<int> ids) { return _context .Set<TEntity>() .IgnoreDeletedEntities() .Where(x => ids.Distinct().Contains(x.ContactId)) .Select(EntityToDTOMapper) .ToList(); } This code throws an error where I use Contains, I saw in some other posts this issues has been fixed as a bug, but yet it fails. Error I get is "could not be