entity-framework

Applying an Expression<> to a LINQ Where clause

淺唱寂寞╮ 提交于 2020-07-23 06:37:34
问题 I'm writing a custom Entity Framework filter. I have a list of IDs, and a user-supplied expression. protected IEnumerable<TColumn> FilterIds; protected Expression<Func<T, IEnumerable<TColumn>, bool>> Filter; Now my question is how do I apply the Filter expression to a Where() clause? public virtual IQueryable<T> ApplyFilter(IQueryable<T> query) { if (FilterMode == FilterModeMatchAny && HasFilterIds) { // Whoops! Can't do this! return query.Where(x => Filter(x, FilterIds)); } return query; 回答1

Applying an Expression<> to a LINQ Where clause

我与影子孤独终老i 提交于 2020-07-23 06:36:12
问题 I'm writing a custom Entity Framework filter. I have a list of IDs, and a user-supplied expression. protected IEnumerable<TColumn> FilterIds; protected Expression<Func<T, IEnumerable<TColumn>, bool>> Filter; Now my question is how do I apply the Filter expression to a Where() clause? public virtual IQueryable<T> ApplyFilter(IQueryable<T> query) { if (FilterMode == FilterModeMatchAny && HasFilterIds) { // Whoops! Can't do this! return query.Where(x => Filter(x, FilterIds)); } return query; 回答1

C#: Inherit from DbContext in Net Core, Constructor: No database provider has been configured for this DbContext

点点圈 提交于 2020-07-23 06:33:37
问题 I currently have PropertyApplication DbContext as below, public partial class PropertyContext : DbContext { public PropertyContext() { } public PropertyContext(DbContextOptions<PropertyContext> options) : base(options) { } public virtual DbSet<Address> Address { get; set; } public virtual DbSet<BoundaryChangeEvent> BoundaryChangeEvent { get; set; } I would like to inheritance from this PropertyDbContext. Is this being done correctly in the constructor? Attempting to make unit test pass below,

C#: Inherit from DbContext in Net Core, Constructor: No database provider has been configured for this DbContext

你离开我真会死。 提交于 2020-07-23 06:31:29
问题 I currently have PropertyApplication DbContext as below, public partial class PropertyContext : DbContext { public PropertyContext() { } public PropertyContext(DbContextOptions<PropertyContext> options) : base(options) { } public virtual DbSet<Address> Address { get; set; } public virtual DbSet<BoundaryChangeEvent> BoundaryChangeEvent { get; set; } I would like to inheritance from this PropertyDbContext. Is this being done correctly in the constructor? Attempting to make unit test pass below,

.net 5 is not available in Visual Studio 2019

牧云@^-^@ 提交于 2020-07-20 20:27:06
问题 I have downloaded and installed .NET Core 5.0 SDK (v5.0.100-preview.1) in my Visual Studio 2019. But it is not available in Target framework. Am I missing something? 回答1: You need to install the latest preview of Visual Studio 2019 16.6 , refer to https://devblogs.microsoft.com/aspnet/asp-net-core-updates-in-net-5-preview-1/ You also need to explicitly enable preview versions within Visual Studio itself: Then you should see it: 来源: https://stackoverflow.com/questions/60843091/net-5-is-not

PostgresException: 23505: duplicate key value violates unique constraint “PK_country”

点点圈 提交于 2020-07-18 20:58:20
问题 I am using EF Core 2.0 and Postgres 9.6. Whenever I insert data I get the error PostgresException: 23505: duplicate key value violates unique constraint "PK_country" By tracing it looks like EF doesnt generate AutoIncrement column My Model public partial class Country { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int CountryId { get; set; } [Display(Name="Country Name")] public string CountryName { get; set; } } My Controller if (ModelState.IsValid) { _context.Add

PostgresException: 23505: duplicate key value violates unique constraint “PK_country”

烈酒焚心 提交于 2020-07-18 20:57:04
问题 I am using EF Core 2.0 and Postgres 9.6. Whenever I insert data I get the error PostgresException: 23505: duplicate key value violates unique constraint "PK_country" By tracing it looks like EF doesnt generate AutoIncrement column My Model public partial class Country { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int CountryId { get; set; } [Display(Name="Country Name")] public string CountryName { get; set; } } My Controller if (ModelState.IsValid) { _context.Add

Entity Framework Core hierarchyid

℡╲_俬逩灬. 提交于 2020-07-18 10:15:07
问题 I'm trying to use EF Core but I need to use the sql server datatype hierarchyid on one of my tables. Is it possible to designate a field in my c# class to be of type hierarchyid? Could I manually column EF creates to be type hierarchyid without breaking EF? Edit: I have tried to do this: public class Entity { public int Id { get; set; } public string Name { get; set; } public SqlHierarchyId HierarchyId { get; set; } } As it's suggested that this is supported by EF core 2.1, however when i run

How DbMigrationsConfiguration is related to a DbMigration in EF

倾然丶 夕夏残阳落幕 提交于 2020-07-18 09:31:17
问题 In Entity Framework by using Enable-Migrations a Migrations folder is created containing a Configuration inherited from DbMigrationsConfiguration like this: internal sealed class Configuration : DbMigrationsConfiguration<MyDbContext> { ... } All the created migrations which are created using Add-Migration are placed in the Migrations folder too. public partial class Init: DbMigration { public override void Up() { ... } public override void Down() { ... } } I didn't find any code that relates

IDbAsyncQueryProvider in EntityFrameworkCore

自古美人都是妖i 提交于 2020-07-18 09:15:11
问题 I'm using XUNIT to test in a dot net core application. I need to test a service that is internally making an async query on a DbSet in my datacontext. I've seen here that mocking that DbSet asynchronously is possible. The problem I'm having is that the IDbAsyncQueryProvider does not seem to be available in EntityframeworkCore, which I'm using. Am I incorrect here? Has anyone else got this working? (Been a long day, hopefully I'm just missing something simple) EDIT After asking on GitHub, I