@@ -67,6 +67,8 @@ static void Main(string[] args)
67
67
var config = ParsingConfig . DefaultEFCore21 ;
68
68
69
69
var context = new TestContext ( ) ;
70
+ //context.Database.EnsureDeleted();
71
+ //context.Database.EnsureCreated();
70
72
if ( ! context . Cars . Any ( ) )
71
73
{
72
74
context . Cars . Add ( new Car { Brand = "Ford" , Color = "Blue" , Vin = "yes" , Year = "2017" } ) ;
@@ -76,13 +78,37 @@ static void Main(string[] args)
76
78
context . SaveChanges ( ) ;
77
79
}
78
80
81
+ if ( ! context . Brands . Any ( ) )
82
+ {
83
+ context . Brands . Add ( new Brand { BrandType = "Ford" , BrandName = "Fiesta" } ) ;
84
+ context . Brands . Add ( new Brand { BrandType = "Fiat" , BrandName = "Panda" } ) ;
85
+ context . Brands . Add ( new Brand { BrandType = "Alfa" , BrandName = "Romeo" } ) ;
86
+ context . SaveChanges ( ) ;
87
+ }
88
+
79
89
//var g1 = context.Cars.GroupBy("new(Brand)").Select("new(Key.Brand as KeyValue1, it.Count() as CountValue1)").ToDynamicList();
80
90
//Console.WriteLine("GroupBy @ local {0}", JsonConvert.SerializeObject(g1, Formatting.Indented));
81
91
82
92
//Console.WriteLine(new string('_', 80));
83
93
84
- var g2 = context . Cars . GroupBy ( "new(Brand)" , config ) . Select ( "new(Key.Brand as KeyValue2, it.Count() as CountValue2)" ) . ToDynamicList ( ) ;
85
- Console . WriteLine ( "GroupBy @ database {0}" , JsonConvert . SerializeObject ( g2 , Formatting . Indented ) ) ;
94
+ //var g2 = context.Cars.GroupBy("new(Brand)", config).Select("new(Key.Brand as KeyValue2, it.Count() as CountValue2)").ToDynamicList();
95
+ //Console.WriteLine("GroupBy @ database {0}", JsonConvert.SerializeObject(g2, Formatting.Indented));
96
+
97
+ var join1 = context . Cars . Join (
98
+ context . Brands ,
99
+ c => c . Brand ,
100
+ b => b . BrandType ,
101
+ ( c , b ) => new { Brand = b , Car = c } )
102
+ . GroupBy ( g => g . Car . Year ) ;
103
+ Console . WriteLine ( "join1 @ database {0}" , JsonConvert . SerializeObject ( join1 , Formatting . Indented ) ) ;
104
+
105
+ var join2 = context . Cars . Join (
106
+ context . Brands ,
107
+ "it.Brand" ,
108
+ "BrandType" ,
109
+ "new(outer as Car, inner as Brand)" )
110
+ . GroupBy ( "Car.Year" ) ;
111
+ Console . WriteLine ( "join2 @ database {0}" , JsonConvert . SerializeObject ( join2 , Formatting . Indented ) ) ;
86
112
87
113
//var carFirstOrDefault = context.Cars.Where(config, "Brand == \"Ford\"");
88
114
//Console.WriteLine("carFirstOrDefault {0}", JsonConvert.SerializeObject(carFirstOrDefault, Formatting.Indented));
0 commit comments