[英]How to join between IdentityUser DbSet and other DbSet
我正在嘗試使用 linkq 在 ApplicationUser (從 IdentityUser 繼承)和另一個模式之間加入。 我的應用程序用戶 class:
namespace ServiceProviderApp.Models
{
public class ApplicationUser : IdentityUser
{
public ApplicationUser() : base() { }
public string Name { get; set; }
public string Address { get; set; }
public string Photo { get; set; }
public string BusinessName { get; set; }
}
}
我的應用上下文文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using ServiceProviderApp.Models;
using ServiceProviderApp;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
namespace ServiceProviderApp.Models
{
public class ServiceProviderAppContext : IdentityDbContext<ApplicationUser,ApplicationRole,string>
{
public ServiceProviderAppContext (DbContextOptions<ServiceProviderAppContext> options)
: base(options)
{
}
public DbSet<ServiceProviderApp.Models.Provider> Provider { get; set; }
...
...
...
...
public DbSet<ServiceProviderApp.Models.ApplicationUser> ApplicationUser { get; set; }
public DbSet<ServiceProviderApp.Models.ApplicationRole> ApplicationRole { get; set; }
}
}
我有以下文件:
public class DummyData
{
public static async Task Initialize(ServiceProviderAppContext context)
{
context.Database.EnsureCreated();
var q = from p in context.Provider
join au in context.ApplicationUser on p.ProviderId equals au.Id
where au.Email == "mm@mm.mm" select au.id;
.....................
在 linq 查詢中,“加入”被標記為錯誤,我收到以下錯誤:
join 子句中的表達式之一的類型不正確。 對“加入”的調用中的類型推斷失敗。 異常:ArgumentNullException。
我在編譯時而不是在運行時收到此錯誤。
列的數據類型不同(字符串與整數),因此,我不得不提一下 IdentityUser 的 PK 類型: IdentityUser<int>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.