entity-framework-core

Using EF Core HasQueryFilter on navigation properties

℡╲_俬逩灬. 提交于 2021-02-20 13:52:57
问题 I'm trying to apply a filter to my queries for multi-tenancy but it doesn't allow me to apply the filter when the property is part of a navigation property: modelBuilder.Entity<Level>().HasQueryFilter(lvl => lvl.SchoolYear.TenantId == _tenantProvider.TenantId); Here, Level is the property I want filtered but the property to use for filtering which is TenantId is is inside Level.SchoolYear. If its a top-level property it works fine. How can I apply a global filter when the property I need for

How can I switch the database provider used by EF Core based on configuration?

孤者浪人 提交于 2021-02-20 00:25:51
问题 EF Core supports a lot of different providers and I can configure them in Startup.cs by specifying the provider. For example, if I want to use SQL Server, I can use: services.AddDbContext<SomeContext>(options => { options.UseSqlServer(Configuration.GetConnectionString("SomeDatabase")); }); But the DB provider (SQL Server) seems to be hard-coded here. What I want to achieve is set the DB provider based on configuration so I can switch the DB provider based on configuration. Is there a way to

How can I switch the database provider used by EF Core based on configuration?

妖精的绣舞 提交于 2021-02-20 00:25:34
问题 EF Core supports a lot of different providers and I can configure them in Startup.cs by specifying the provider. For example, if I want to use SQL Server, I can use: services.AddDbContext<SomeContext>(options => { options.UseSqlServer(Configuration.GetConnectionString("SomeDatabase")); }); But the DB provider (SQL Server) seems to be hard-coded here. What I want to achieve is set the DB provider based on configuration so I can switch the DB provider based on configuration. Is there a way to

How can I switch the database provider used by EF Core based on configuration?

限于喜欢 提交于 2021-02-20 00:24:53
问题 EF Core supports a lot of different providers and I can configure them in Startup.cs by specifying the provider. For example, if I want to use SQL Server, I can use: services.AddDbContext<SomeContext>(options => { options.UseSqlServer(Configuration.GetConnectionString("SomeDatabase")); }); But the DB provider (SQL Server) seems to be hard-coded here. What I want to achieve is set the DB provider based on configuration so I can switch the DB provider based on configuration. Is there a way to

How can I switch the database provider used by EF Core based on configuration?

主宰稳场 提交于 2021-02-20 00:22:45
问题 EF Core supports a lot of different providers and I can configure them in Startup.cs by specifying the provider. For example, if I want to use SQL Server, I can use: services.AddDbContext<SomeContext>(options => { options.UseSqlServer(Configuration.GetConnectionString("SomeDatabase")); }); But the DB provider (SQL Server) seems to be hard-coded here. What I want to achieve is set the DB provider based on configuration so I can switch the DB provider based on configuration. Is there a way to

How to lower memory usage in FileStreamResult api

China☆狼群 提交于 2021-02-19 08:37:11
问题 Right now I have an api that gets many results (800k) and it should parse and stream them as CSV. The (kind of) working code I have is this var query = context.address.AsNoTracking(); MemoryStream memoryStream = new MemoryStream(); StreamWriter writer = new StreamWriter(memoryStream); foreach (var row in query) { writer.WriteLine(row.Name+","+row.Surname+","+row.BirthDate); } writer.Flush(); memoryStream.Seek(0, SeekOrigin.Begin); return new FileStreamResult(memoryStream, "application/octet

EF Core 3.1.1 Avoiding the exception “The data types text and varchar are incompatible in the equal to operator” just as LINQPad 6 does

Deadly 提交于 2021-02-19 08:04:09
问题 I am trying to run this LINQ expression through Entity Framework Core 3.1.1. using (Text3Context text3Context = new Text3Context(_constringText3)) { var aus = text3Context.Ausschreibungen.Where(a => a.InhaltKurzText.Contains(value)).Select(c => c.InhaltKurzText).ToList(); } Unfortunately it throws the exception: "The data types text and varchar are incompatible in the equal to operator" however, when I run the same expression in LINQPad 6: string value = "test"; var aus = Ausschreibungen

Entity Framework Core Linq query to filter related entity

随声附和 提交于 2021-02-19 02:32:19
问题 I've been figuring out a long time on how to write a query on filtering related entity through Entity Framework Core while using Include, suppose I have following two class: public class Order { public int OrderId {get; set;} public String CreatedBy{get; set;} public virtual Collection<OrderDetail> OrderDetails { get; set; } = new Collection<OrderDetail>(); } public class OrderDetail { public Int64? OrderDetailID { get; set; } public Int64? OrderID { get; set; } public string ProductName {

Sorting using property name as string

倖福魔咒の 提交于 2021-02-18 12:25:08
问题 I would like my Web API to be able to sort its output by a string parameter such as this one: http://myapi.com/api/people?skip=0&take=50&orderBy=lastName&descending=true . Because I also have pagination support (with skip and take ) in my API, I would like the orderBy and descending parameter to be applied to the SQL query directly, so that the correct result comes from the database. When doing this however, the code can become very hard to manage when trying to match the parameters for

Store user data in auth server or resource server? Or both?

痞子三分冷 提交于 2021-02-18 11:33:30
问题 This is my first time setting up OpenID Connect with IdentityServer 4 and AspNetIdentity and I was hoping someone could demystify the part about storing user data. What I've read so far is that user data should be stored in the Auth db that is connected to the auth server, but I'd really like to store user data in the resource db too that is connected to the resource server. I currently have a data model that looks like this: I have omitted many of the fields for both User and Event, but you