Tag: ef core 2.0

在ASP.NET Core中实现OrganizationUnitfilter

在ASP.NET Boilerplate中,有像Tenantfilter这样的内置数据filter,我们可以使用SetTenantId来启用查询特定的tenantId 。 根据官方文档,与EF 6.x不同,它不支持EF Core中的自定义Filter 。 我想知道如何为OrganizationUnitId参数实现类似的filter。 这是我到目前为止所做的: 覆盖CreateFilterExpression : protected override Expression<Func> CreateFilterExpression() { Expression<Func> expression = null; if (typeof(IMayHaveOrganizationUnit).IsAssignableFrom(typeof(TEntity))) { Expression<Func> mayHaveOUFilter = e => ((IMayHaveOrganizationUnit)e).OrganizationUnitId == CurrentOrganizationUnitId || (((IMayHaveOrganizationUnit)e).OrganizationUnitId == CurrentOrganizationUnitId) == IsMayHaveOrganizationUnitFilterEnabled; expression = expression == null ? mayHaveOUFilter : CombineExpressions(expression, mayHaveOUFilter); } expression = expression == null ? base.CreateFilterExpression() […]

Azure Functions .NET Core中的EF Core 2.0连接字符串

我使用.net核心在Azure Functions中使用EF core 2.0。 我正在尝试从local.settings.json读取db ConnectionString,其定义如下: { “IsEncrypted”: false, “Values”: { “AzureWebJobsStorage”: “UseDevelopmentStorage=true”, “AzureWebJobsDashboard”: “UseDevelopmentStorage=true” }, “ConnectionStrings”: { “MyDbConnStr”: “Data Source=.;Initial Catalog=xxxxxxx” } } Environment.GetEnvironmentVariable()不返回任何连接字符串信息,我也不能使用带有.net核心的ConfigurationManager.ConnectionStrings。 如何从代码中访问连接字符串?

EF Core中是否有唯一约束的数据注释(代码优先)?

我想知道在Entity Framework Core 2代码第一种方法中是否存在唯一约束的数据注释?

entity framework核心在转换时是延迟加载的

在将实体模型转换为DTO时,我遇到了Entity Framework Core(v2.0.1)的问题。 基本上,它是由任何其他版本的短语,懒惰加载,当我不想要它。 这是一个简单的.NET Core Console应用程序(使用Microsoft.EntityFrameworkCore.SqlServer(2.0.1)包)。 using Microsoft.EntityFrameworkCore; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; namespace EfCoreIssue { class Program { static void Main(string[] args) { var dbOptions = new DbContextOptionsBuilder() .UseSqlServer(“Server=.;Database=EfCoreIssue;Trusted_Connection=True;”) .Options; // Create and seed database if it doesn’t already exist. using (var dbContext = new ReportDbContext(dbOptions)) { if (dbContext.Database.EnsureCreated()) { […]

EF Core:使用阴影属性和查询filter进行软删除

我创建了一个界面来尝试进行软删除,混合阴影属性和查询filter。 但它不起作用。 public interface IDeletableEntity {} 然后在我的模型构建器中 builder.Model.GetEntityTypes() .Where(entityType => typeof(IDeletableEntity).IsAssignableFrom(entityType.ClrType)) .ToList() .ForEach(entityType => { builder.Entity(entityType.ClrType).Property(“IsDeleted”); builder.Entity(entityType.ClrType).HasQueryFilter(e => EF.Property(e, “IsDeleted”) == false); }); 但是查询filter的行不能编译。 我得到的错误是“无法将lambda表达式转换为’lambda表达式’,因为它不是委托类型” 如果我这样做它的工作。 builder.Entity().HasQueryFilter(m => EF.Property(m, “IsDeleted”) == false); 有什么方法可以做到这一点? 这是为了在我想要使用软删除实体的每个实体中都有一个IDeletableEntity接口而不必这样做 提前谢谢了,