【问题标题】:How to join between IdentityUser DbSet and other DbSet如何在 IdentityUser DbSet 和其他 DbSet 之间加入
【发布时间】:2019-10-10 18:11:16
【问题描述】:

我正在尝试使用 linkq 连接 ApplicationUser(继承自 IdentityUser)和另一个架构。我的 ApplicationUser 类:

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”被标记为错误,我收到以下错误:

join 子句中的一个表达式的类型不正确。对“加入”的调用中的类型推断失败。异常:ArgumentNullException。

我在编译时而不是在运行时收到此错误。

【问题讨论】:

    标签: c# .net mvcc


    【解决方案1】:

    列的数据类型不同(字符串与整数),因此,我不得不提到 IdentityUser 的 PK 类型:IdentityUser&lt;int&gt;

    【讨论】:

      猜你喜欢
      • 2020-10-29
      • 2017-07-19
      • 2014-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-17
      • 1970-01-01
      • 2017-03-21
      相关资源
      最近更新 更多