[英]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.