entity-framework-core

Express query with multiple OR and filter on joined table with Entity Framework Core

妖精的绣舞 提交于 2021-01-28 14:09:06
问题 Here is my model class Parent { int Id; string Name; List<Child> Childs; } // name is unique class Child { int Id; int ParentId; string Name; Parent Parent; } // couple (id, name) is unique With a given list of couples (parent name, child name) I'd like to get the couples (parent, child) where child can be null if the parent with the given name exists but not the child. The SQL query would look like this: SELECT * FROM parents p LEFT JOIN childs c ON c.parent_id = p.id WHERE p.name = 'parent1

UWP project not compatible with netcoreapp2.1

若如初见. 提交于 2021-01-28 12:31:57
问题 I created an UWP app and I will use entityFrameworkCore to create my DB with code first. My app console (entityFrameworkCore app) works and creates my DB but when I make a reference to my UWP project it doesn't work and shows this error: The project uwp is not compatible with netcoreapp2.1(.NETCoreApp,version=v2.1) And when i would like add a reference in uwp to db project i have this error enter image description here 回答1: A .NET Core app cannot add a reference to a UWP app and vice versa.

Ef core 5 many to many filter

十年热恋 提交于 2021-01-28 09:02:05
问题 This is my query public async Task<IEnumerable<Menu>> GetMenuByRolesAsync(string[] roles) { var result= await _context.Menus//.Include(o => o.Parent) .Include(m => m.Childrens) .ThenInclude(m => m.Childrens) .Include(m => m.Roles.Where(r => roles.Contains(r.Name))) --it is not filtering basd on roles .Where(m => m.ParentId == null) .ToListAsync(); } It is generating below query -- @__roles_0='System.String[]' (DbType = Object) SELECT m.id, m.icon, m.name, m.parent_id, m.url, t.role_id, t.menu

Entity Framework Core migrations through CI and CD in Azure DevOps

眉间皱痕 提交于 2021-01-28 08:39:53
问题 I have created an Entity Framework Core project and it is working fine and I am able to generate migrations through Visual Studio. But I want to generate SQL scripts through Azure Devops CI and deployment through CD. I am unable to do it. By adding this command dotnet ef migrations script --project $(Build.SourcesDirectory)\SampleEFCoreApplication\SampleEFCoreApplication.csproj -o $(build.artifactstagingdirectory)\migrations\scripts.sql This generates the entire SQL script. But next time, if

EF Core context not disposing of change tracking entities

和自甴很熟 提交于 2021-01-28 08:18:05
问题 Using EF Core 2.1 to insert 135k records. Once the request is finished, I would expect the context to be disposed of and along with it, the ChangeTracking entities to be cleared, however, it's holding on to all 135k records and using a lot of memory in the process. We are using ASP.NET Core 2.1 and injecting the EF Context from the DI container. Since the DI container should dispose of the scoped context at the end of the request, it should not be holding on to these values. Even calling

How to fix: In Azure Devops connection string is null despite setting Variable in the build Pipeline

≡放荡痞女 提交于 2021-01-28 07:38:20
问题 I have problem with build pipeline in Azure Devops, with variables from build pipeline not replacing empty configuration in appsettings.json. Below there is more details. My current test project is build using asp.net core technology and is connected to SQL server. I also use Entity Framework Core and autofac. To connect to SQL server I use appsettings.json configuration: { "ConnectionStrings": { "AzureDbConnectionString": "" } } but my credentials are stored in secrets.json {

C# - Using Entity Framework Core 3 HasConversion to convert a field to JSON in .Net Core 3.1

↘锁芯ラ 提交于 2021-01-28 06:02:39
问题 I was trying to accomplish the conversion dynamically across all of the models I have in my project: DbContext.cs protected override void OnModelCreating(ModelBuilder modelBuilder) { var entityTypes = modelBuilder.Model.GetEntityTypes().ToList(); foreach (var entityType in entityTypes) { foreach (var property in entityType.ClrType.GetProperties().Where(x => x != null && x.GetCustomAttribute<HasJsonConversionAttribute>() != null)) { modelBuilder.Entity(entityType.ClrType) .Property(property

ShadowProperties being reached by foreach before being created

只谈情不闲聊 提交于 2021-01-28 05:04:44
问题 I'm new to Entity Framework and I'm learning atm with the Pluralsight courses from Julie Lerman. I'm watching the 2nd course "Entity Framework Core 2: Mappings" but I'm using EF Core 2.1. Edit: So I decided comment everything out and follow the course again and it is working now BUT the generated migration in generating 2 columns that shouldn't be there: protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn<DateTime>( name: "BetterName_Created", table:

Set column names during OnModelCreating

折月煮酒 提交于 2021-01-28 02:51:06
问题 Issue I am currently trying to prefix my tables and their columns via an attribute that is set. I am using Entity Framework Core. I've gotten it right to prefix the table name but I cannot seem to figure it out for the columns. I have a feeling I will need to use reflection. I have left my (probably poor) attempt at reflection in. Does someone have a way of setting the name of a column in an entity? Code protected override void OnModelCreating(ModelBuilder modelBuilder) { Debugger.Launch(); /

How to set default values for shadow property

℡╲_俬逩灬. 提交于 2021-01-28 01:09:52
问题 I have the following entity: public class Person { public Guid Id { get; set; } public string Name { get; set; } } This is my DB context public class PersonDbContext : DbContext { private static readonly ILoggerFactory Logger = LoggerFactory.Create(x => x.AddConsole()); public DbSet<Person> Persons { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder .UseLoggerFactory(Logger) .UseSqlServer( "Server=(localdb)\\mssqllocaldb;Database