Exemple #1
0
        //max

        //join  查询国贸大厦C座,商业面积大于200平米的商铺
        public static void TestLinqJoin()
        {
            Console.WriteLine("------查询国贸大厦C座,商业面积大于200平米的商铺------");
            var buildLst   = BuildFactory.CreatBuilds();
            var unitlst    = BuildFactory.CreatUnits();
            var BuildUnits = from unit in unitlst
                             join build in buildLst
                             on unit.BuildId equals build.BuildId
                             where build.Name == "国贸大厦C座"
                             select new
            {
                BuildName      = build.Name,
                BuildHeight    = build.Height,
                UnitName       = unit.Name,
                UnitArea       = unit.Area,
                UnitFloorIndex = unit.FloorIndex
            } into newBuildUnits
            where newBuildUnits.UnitArea > 200
            select newBuildUnits;

            foreach (var item in BuildUnits)
            {
                Console.WriteLine(string.Format("单位名称:{0},楼层:{1},商业面积:{2},建筑名称:{3},建筑高度:{4}",
                                                item.UnitName, item.UnitFloorIndex, item.UnitArea, item.BuildName, item.BuildHeight));
            }
            Console.ReadKey();
        }
Exemple #2
0
        //group 利用分组计算建筑所属单位的商业总面积
        public static void TestLinqGroup()
        {
            Console.WriteLine("------利用分组计算建筑所属单位的商业总面积------");
            var buildLst   = BuildFactory.CreatBuilds();
            var unitlst    = BuildFactory.CreatUnits();
            var BuildUnits = from unit in unitlst
                             join build in buildLst on unit.BuildId equals build.BuildId
                             select new { unit.Area, unit.BuildId, build.Name } into newBuildUnits
            group newBuildUnits by newBuildUnits.BuildId into g
                select new { BuildName = g.Select(p => p.Name).First(), TotalArea = g.Sum(p => p.Area) };

            foreach (var item in BuildUnits)
            {
                Console.WriteLine(string.Format("建筑名称:{0},商业总面积:{1}", item.BuildName, item.TotalArea));
            }
            Console.ReadKey();
        }