第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

擴(kuò)展方法中的表達(dá)式樹(shù)將在本地評(píng)估

擴(kuò)展方法中的表達(dá)式樹(shù)將在本地評(píng)估

C#
撒科打諢 2022-06-18 17:38:54
我想將 TenantId 添加到 Asp.Net 身份表(例如:用戶)。以下代碼段工作正常。租戶上下文將通過(guò) DI 注入,租戶根據(jù) http 上下文域進(jìn)行更改:private readonly ITenantContext<ApplicationTenant> tenantContext;public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options, ITenantContext<ApplicationTenant> tenantContext) : base(options){    this.tenantContext = tenantContext;}protected override void OnModelCreating(ModelBuilder builder){    base.OnModelCreating(builder);    builder.Entity<ApplicationUser>(b =>    {        // add tenant        b.Property(typeof(int), "TenantId");        b.HasQueryFilter(x => EF.Property<int>(x, "TenantId") == this.tenantContext.Tenant.Id);    });}為了重用,我想為 entityBuilder 創(chuàng)建一個(gè)擴(kuò)展方法:public static class EntityTypeBuilderExtensions{    public static void AddTenancy<TEntity>(        this EntityTypeBuilder<TEntity> builder,        Expression<Func<int>> tenantId,        string propertyName = "TenantId")        where TEntity : class    {        // validate        Ensure.Argument.NotNull("builder", builder);        // add property to entity        builder.Property(typeof(int), propertyName).IsRequired();        /* THIS WORKS BUT WILL BE EVALUATED LOCALLY */        // left        var parameterExp = Expression.Parameter(typeof(TEntity), "x"); // e = TEntity => e.g: User        var propertyNameExp = Expression.Constant(propertyName, typeof(string)); // the name of the tenant column - eg.: TenantId    }}擴(kuò)展方法也可以正常工作,但表達(dá)式是在本地評(píng)估的:-(。有人可以幫我修復(fù)它嗎?LINQ 表達(dá)式 'where (Property([x], "TenantId") == Invoke(__ef_filter__tenantId_0))' 無(wú)法翻譯,將在本地進(jìn)行評(píng)估。無(wú)法翻譯 LINQ 表達(dá)式“where ([x].NormalizedUserName == __normalizedUserName_0)”并將在本地進(jìn)行評(píng)估。無(wú)法翻譯 LINQ 表達(dá)式“FirstOrDefault()”并將在本地進(jìn)行評(píng)估。
查看完整描述

1 回答

?
倚天杖

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超3個(gè)贊

問(wèn)題出Func在這里


private Func<int> tenantId => ...

這導(dǎo)致翻譯Invoke(__ef_filter__tenantId_0))和客戶評(píng)價(jià)不佳。


解決方案是制作tenantId簡(jiǎn)單的int返回屬性或方法。例如,保持通話


b.AddTenancy(() => this.tenantId(), "TenantId");

它應(yīng)該改為


private int tenantId()

{

    // return tenant id

    if (this.tenantContext != null && this.tenantContext.Tenant != null)

    {

        return this.tenantContext.Tenant.Id;

    }


    return -1;

};


查看完整回答
反對(duì) 回復(fù) 2022-06-18
  • 1 回答
  • 0 關(guān)注
  • 123 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)