0

我有以下架构:

public class Provider
    {

        [Key]
        public int ProviderId { get; set; }
        [ForeignKey("ProviderId")]
        public ApplicationUser User;

        public ICollection<ServiceProvider> Services { get; set; }
    }

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

在我的后端,我有一封电子邮件作为输入,我正在尝试检查是否有任何提供该电子邮件的提供商。我尝试使用以下代码:

if (context.Provider.Any(o => o.User.Email == input_mail) == false)

但我有一个空指针异常..

我知道我可以使用 linku 语法:

    var q = from au in _context.ApplicationUser
            join p in _context.Provider on au.Id equals p.ProviderId
            where au.Email=input_mail;

有什么方法可以使用模型上下文来做到这一点?而不是链接

4

2 回答 2

0

如果我理解您的问题,那么以下句子就足够了,无需添加 FALSE if (context.Provider.Any(o => o.User.Email == input_mail))

于 2019-10-10T17:29:40.110 回答
0

覆盖电子邮件并在模型中测试它是否为空。

// Override auto-implemented property with ordinary property
   // to provide specialized accessor behavior.
    public override string Email
    {
        get
        {
            return email;//declare this private string also in model
        }
        set
        {
            if (!string.IsNullOrEmpty(value))
            {
                name = value;
            }
            else
            {
                email= "Unknown";
            }
        }
    } 
于 2019-10-10T17:35:55.230 回答