简体   繁体   English

存储库模式多个选择器

[英]Repository Pattern Multiple selectors

Using a UnitOfWork Repository pattern I can access a reference using : 使用UnitOfWork存储库模式,我可以使用以下命令访问引用:

var tmp = unitOfWork.Repository<User>().Queryable();

I wish to query the table and recover an account where AccountId is an long: 我希望查询表并恢复一个AccountId长的帐户:

result = a.Any(e => e.AccountId == AccountId);

This provides me with a record of the account for AccountId . 这为我提供了AccountId帐户的记录。

I also have a table called Emails which is linked to the Account table. 我还有一个名为Emails的表,该表链接到Account表。 So I now wish to update the query above to the following: 因此,我现在希望将上面的查询更新为以下内容:

result = a.Any(e => 
    e.AccountId == AccountId &&
    e.Email.EmailID == EmailID
);

Where EmailId is a long. 其中EmailId很长。 This should now pull an specific Email for a specific user account. 现在,这应该为特定的用户帐户提取特定的电子邮件。

What I get is: 我得到的是:

Operator '&&' cannot be applied to operands of type 'bool' and 'User'

It's not clear exactly what you want, but 目前尚不清楚您想要什么,但是

var tmp = unitOfWork.Repository<User>().Queryable();

should give you IQueryable<User> on which you can apply Where conditions, but you'll get result of User collection or object. 应该为您提供IQueryable<User> ,您可以在其上应用Where条件,但是您将获得User集合或对象的结果。

unitOfWork.Repository<User>().Queryable().Where(e => 
    e.AccountId == AccountId &&
    e.Email.EmailID == EmailID
);

If you want Email you should either load the Email with User object above or apply your condition on unitOfWork.Repository<Email>().Queryable(); 如果要使用Email ,则应加载上面的带User Email对象,或将条件应用于unitOfWork.Repository<Email>().Queryable();

I found that if I use the following it works for me. 我发现如果我使用以下内容对我来说很有效。

Result = searchQuery.Any(e =>
                    e.AccountId == AccountId &&
                    e.Email.Any(f => f.Id == EmailId);

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

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