简体   繁体   English

如何在 IdentityUser DbSet 和其他 DbSet 之间加入

[英]How to join between IdentityUser DbSet and other DbSet

I'm trying to use linkq to join between the ApplicationUser (inherits from IdentityUser) and another schema.我正在尝试使用 linkq 在 ApplicationUser (从 IdentityUser 继承)和另一个模式之间加入。 My ApplicationUser class:我的应用程序用户 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; }
    }
}

My app context file:我的应用上下文文件:

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; }
    }
}

I have the following file:我有以下文件:

 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;

.................... .....................

In the linq query the "join" is marked as an error and I'm getting the following error:在 linq 查询中,“加入”被标记为错误,我收到以下错误:

The type of one of the expressions in the join clause is incorrect. join 子句中的表达式之一的类型不正确。 Type inference failed in the call to 'Join'.对“加入”的调用中的类型推断失败。 Exceptions: ArgumentNullException.异常:ArgumentNullException。

I'm getting this error in compile time and not in run time.我在编译时而不是在运行时收到此错误。

The datatype of the columns was different (string vs int), therefore, I had to mention implecity the PK type of IdentityUser: IdentityUser<int>列的数据类型不同(字符串与整数),因此,我不得不提一下 IdentityUser 的 PK 类型: IdentityUser<int>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM