using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace hashmap { class A { public string name { get; set; } public string age { get; set; } } class Program { static void Main(stri…
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { List<string> strarr = new List<string>() { &q…
Dim g = lst.Data.GroupBy(Function(T) New With { Key T.mName, Key T.mUnit, Key T.mPrice }).Select(Function(t) New With { .mName = t.Key.mName, .mPrice = t.Key.mPrice, .mUnit = t.Key.mUnit, .mValue = t.Sum(Function(i) i.mValue) }) c#版本对照 { var g = lst.…
闲暇之余,整理了一下EF底层的一些基础方法,供查看,只有接口,具体实现需要你们自己写了. 建议:接口的实现定义为虚方法,当父类的方法不满住子类需求时,可以重写此方法 此接口都为公用方法,基本上满足小系统的实际开发需求,如果你觉得满足不了你,可以扩展此接口. using System; using System.Collections.Generic; using System.Data; using System.Data.Entity; using System.Data.SqlClient;…
LINQ: var temp = from p in db.jj_Credentials group p by p.ProfessionID into g select new { g.Key, MaxPrice = g.Max(p => p.CredentialsRankID) }; EF: var temp1 = db.jj_Credentials.GroupBy(m => m.ProfessionID).Select(m => m.Max(o => o.Credentials…
SELECT COUNT(l.LogSeq), date_format(l.CreateDate,'%Y-%m') CreateDateByMonth FROM LOL l WHERE l.CreateDate>='2017-1-1' AND l.CreateDate<='2017-8-16' GROUP BY CreateDateByMonth 把数据按照月份分组获取所需要的数据SQL语句变为EF,错误的写法: //先做基本查询 var querySql = from l in LOL se…
1.复杂查询运算符 在生产场景中,我们经常用到LINQ运算符进行查询获取数据,现在我们就来了解下生产场景经常出现几种复杂查询运算符. 1.1联接(INNER JOIN) 借助LINQ Join运算符,可根据每个源的键选择器连接两个数据源,并在键匹配时生成值的元组. var query = from blog in _context.Set<Blog>() join post in _context.Set<Post>() on blog.BlogId equals post.Blo…
想用ef来写一个统计字段的语句,如下所示 select sum(price) as price_total, sum(amount) as amount_total from table1 发现似乎实现不了,ef只能 dbContext.Table.Sum(e=>e.price);dbContext.Table.Sum(e=>e.amount)这样一个一个查,没办法一次查询多个聚合函数字段 经过我的研究后,我发现可以曲线救国. dbContext.). Select(g => new {…