c# - 使用模型对象进行 mvc 连接
问题描述
我有以下架构:
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;
有什么方法可以使用模型上下文来做到这一点?而不是链接
解决方案
如果我理解您的问题,那么以下句子就足够了,无需添加 FALSE if (context.Provider.Any(o => o.User.Email == input_mail))
推荐阅读
- javascript - 使用 JavaScript 读取文本文件并实时更新浏览器中的值
- docker - Docker for Windows 和 WSL1 协同工作
- android - Android的Jetpack DataStore(alpha07版本)的正确实例创建
- swift - 使用关系和谓词访问 Core Data 中的数据
- python - 如何循环单击按钮然后向下单击
- r - 数据框中是否可以有一系列数字?
- java - 如何让用户使用正则表达式 java 输入某种格式
- python - 对象不显示可用方法
- javascript - 反应内存泄漏 - 当通过传递给提供者的孩子的函数更新上下文提供者中的状态时
- powershell - 为什么“Get-PowerBIDataset”Powershell 命令会为我提供工作区中的所有数据集?