LinQ 多表查询

摘要:
编辑器正在加载…1.oneTT具有字段AABBCC2.twoTT具有字段EEFFBB以连接两个表,Listmul=(from_db.oneTTTjoinbin_db.twoTTTona.BBequalsb.BB其中a.BB!=“”selectnewMulTable{AAA=a.AA,BBB=a.BB,EEE=b.EE,FFF=b.FF})。ToList˂MulTab

编辑器加载中...

1. oneTT有字段AA BB CC

2. twoTT有字段EE FF BB

两个表连接查询,

List<MulTable> mul = (from a in _db.oneTTT
                      join b in _db.twoTTT
                      on a.BB equals b.BB
                      where a.BB != ""
                      select new MulTable
                      {
                          AAA = a.AA,
                          BBB = a.BB,
                          EEE = b.EE,
                          FFF = b.FF
                      }).ToList<MulTable>();



            foreach (MulTable item in mul)
                Console.WriteLine(item.AAA + item.BBB + item.EEE);
class MulTable
    {
        public string AAA = string.Empty;
        public string BBB = string.Empty;
        public string EEE = string.Empty;
        public string FFF = string.Empty;

        public override string ToString()
        {
            return string.Format("AAA: {0}, BBB:{1}, EEE:{2},FFF{3}", AAA, BBB, EEE,FFF);
        }
    }
string[] Weekdays = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
            //see the above code, the IEnumerable<string> WeekdaysWithLength is the explicit object,here var WeekdaysWithLength is implicit object, which will convert by assign type.
           // var WeekdaysWithLength = from W in Weekdays where W.Length > 1 orderby W select W;
            string[] WeekdaysWithLength = (from W in Weekdays where W.Length > 1 orderby W select W).ToArray<string>();
            //listBox1.Items.Clear();
            foreach (string str in WeekdaysWithLength)
                Console.WriteLine(str);

            List<Car> myCars = new List<Car> { 
            new Car{ Color= "Silver", Make="BMW", PetName="Henry", Speed=100},
            new Car{ Color= "Tan", Make="BMW", PetName="Daisy", Speed=90},
            new Car{ Color= "Black", Make="VW", PetName="Mary", Speed=55},
            new Car{ Color= "Rust", Make="Yugo", PetName="Clunker", Speed=5},
            new Car{ Color= "White", Make="Ford", PetName="Melvin", Speed=43}
            };

            List<Car> fastCars = (from fCar in myCars where fCar.Speed > 55 select fCar).ToList<Car>();
            foreach (Car c in fastCars)
                Console.WriteLine(c.PetName);

            //nongeneric
            // non generic collection of Car objects
            ArrayList arCars = new ArrayList{ 
            new Car{ Color= "Silver", Make="BMW", PetName="Henry", Speed=100},
            new Car{ Color= "Tan", Make="BMW", PetName="Daisy", Speed=90},
            new Car{ Color= "Black", Make="VW", PetName="Mary", Speed=55},
            new Car{ Color= "Rust", Make="Yugo", PetName="Clunker", Speed=5},
            new Car{ Color= "White", Make="Ford", PetName="Melvin", Speed=43}
            };

            //convert non generic car object collection to enumerable
            //IEnumerable<Car> myCars = arCars.OfType<Car>();
            //List<Car> fastCars = (from fCar in myCars where fCar.Speed > 55 select fCar).ToList<Car>();
            //foreach (Car c in fastCars)
            //    Console.WriteLine(c.PetName);

免责声明:文章转载自《LinQ 多表查询》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇SpringCloud-OAuth2(二):实战篇echart柱状图下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

淘宝网Open API 入门教程

淘宝网Open API 入门教程 淘宝网的Open API开放将近一年了,越来越多的人(包括已工作的和在校的大学生)都在使用淘宝的Open API,有不少ISV应用已上架盈利了。我也使用淘宝的Open Api也大半年了。不过了,由于阿里软件的文档比较的乱,让很多初学者分不清头绪(注:淘宝网的Open API是开放在阿里软件的一个平台上,是什么服务集群平台吧...

OHC Java堆外缓存详解与应用

1、背景   在当前微服务体系架构中,有很多服务例如,在 特征组装 与 排序等场景都需要有大量的数据支撑,快速读取这些数据对提升整个服务于的性能起着至关重要的作用。   缓存在各大系统中应用非常广泛。尤其是业务程序所依赖的数据可能在各种类型的数据库上(mysql、hive 等),那么如果想要获取到这些数据需要通过网络来访问。再加上往往数据量又很庞大,网络传...

vb.net的数据类型

一,Numeric(数值型)数据类型 Integer 整型 4字节 变量存储为32位整数型,范围从-2147483.648至2147483.648 Long 长整型 8字节 变量存储为64位整数型,范围从-9223372036854775.808至9223372036854775.807 Short 短整型 2字节 变量存储为16位整数型,范围...

Android okHttp网络请求之Retrofit+Okhttp+RxJava组合

Retrofit介绍:   Retrofit和okHttp师出同门,也是Square的开源库,它是一个类型安全的网络请求库,Retrofit简化了网络请求流程,基于OkHtttp做了封装,解耦的更彻底:比方说通过注解来配置请求参数,通过工厂来生成CallAdapter,Converter,你可以使用不同的请求适配器(CallAdapter), 比方说RxJ...

java发起post请求—— body有参/无参

import org.apache.http.HttpEntity; import org.apache.http.HttpStatus; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.CloseableHttpRespon...

ngx_lua 随笔

--[[ test--]]ngx.header.content_type = "text/plain"; --输出头部local user = ngx.var.arg_user -- 定义user变量并获取url中的参数 http://localhost?user=hellolocal sys = ngx.var.server_name -- 获取ngi...