LINQ:从类列表中的过滤ID

发布于 2025-01-20 12:42:19 字数 631 浏览 3 评论 0原文

我有一个客户班级列表,

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

太阳公公是暖光 2025-01-27 12:42:19

我不知道你的存储库中到底有什么,以及它的类型是什么,但你可以尝试这样的事情:

int idYouLookingFor = 1;
var result = this.CustomerRepository
                .Where(c => c.Id == idYouLookingFor);

I don't know what is exactly in your repository, and what is its type, but you could try something like this:

int idYouLookingFor = 1;
var result = this.CustomerRepository
                .Where(c => c.Id == idYouLookingFor);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文