将LINQ与匿名类型一起使用 [英] Using LINQ with an anonymous type

查看:78
本文介绍了将LINQ与匿名类型一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一个项目从使用标准数据库查询转移到使用EF和LINQ.我有一个表,其中包含某些记录,这些记录可用于构建如下查询的查询:

I am moving a project from working with standard DB queries to working with EF and LINQ. I have a table that has certain records that I would use to build a query that would look like the following:

select * from client where city = ...

在我的原始表中,我将从表中提取客户端和城市以建立该查询.
上面的客户和城市也可能完全是另一个表和/或字段.我将如何使用EF和LINQ做同样的事情?这是否有可能,还是我必须建立一个单独的类来处理所有这些逻辑?
上下文中

In my original table, I would be pulling client and city from the table to build that query.
It is also possible that client and city above could be another table and/or field altogether. How would I do the same thing with EF and LINQ? Is this even possible or do I have to build a separate class to handle all of that logic?

from c in context.clients
 where c.city == ....
 select c

推荐答案

您是否要对LINQ查询使用多个数据源?

像这样吗?我正在使用LINQ to Objects,但想法是相同的.

Are you asking about having multiple data sources to a LINQ query?

Something like this? I am using LINQ to Objects but the idea is the same.

//Find the numbers in numbers that are also in values
int[] numbers = new int[] { 2, 4, 6, 7, 8, 9 };
int[] values = new int[] { 2, 3 };

var rez = from n in numbers
          from v in values
          where n == v
          select n;


这篇关于将LINQ与匿名类型一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆