LINQ:从类列表中的过滤ID
我有一个客户班级列表,
class Customers
{
int Id
string Name
}
List<Customers> CustomerList
假设此列表包含10个记录。
我必须从以下回购中通过客户列表中的 id 过滤。我正在尝试从客户列表中获取所有ID,并从CustomerRepostitory获取关联的记录。 CustomerRepository是由EDMX生成的类,它反映了数据库中的客户表。我不知道这样做的方法。这是我编码的不起作用的。
var status = this.CustomerRepository
.Find(o => CustomerList.Id.Contains(o.Id))
.Select(o => new
{
o.Name,
o.CustomerCode,
}) ```
How do I filter records by passing Id coming in CustomerList ?
I have a list of Customers class
class Customers
{
int Id
string Name
}
List<Customers> CustomerList
Lets suppose this list contains 10 records.
I have to filter by the Id in the CustomerList from the following repo. I am trying to get the all the Ids from CustomerList and get associated records from CustomerRepostitory. CustomerRepository is a class generated by edmx which reflects the Customer table in database. I cannot figure out a way to do that. This is what I have coded which is not working.
var status = this.CustomerRepository
.Find(o => CustomerList.Id.Contains(o.Id))
.Select(o => new
{
o.Name,
o.CustomerCode,
}) ```
How do I filter records by passing Id coming in CustomerList ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道你的存储库中到底有什么,以及它的类型是什么,但你可以尝试这样的事情:
I don't know what is exactly in your repository, and what is its type, but you could try something like this: