简体   繁体   中英

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. My ApplicationUser 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:

The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join'. Exceptions: 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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