小编ale*_*vdi的帖子

linq distinct并选择新查询

我有一个问题

var QP = (from a in QProductAllInfo select new { a.Id, a.Title, a.FullTitle}).Distinct();
Run Code Online (Sandbox Code Playgroud)

结果是:

  • 1伊万诺夫伊万
  • 1伊万诺夫伊万
  • 2彼得罗夫彼得
  • 3西多罗夫伊万
  • 3西多罗夫伊万

我需要结果:

  • 1伊万诺夫伊万
  • 2彼得罗夫彼得
  • 3西多罗夫伊万

c# linq windows linq-to-sql winforms

8
推荐指数
1
解决办法
3万
查看次数

如何从List <int>获取重复次数

List<int> ListIdProducts = new List<int>();
var IdProductKey = from a in me.ProductKeywords where a.Keyword == item.Id select a;
 foreach (var item2 in IdProductKey)
 {
   ListIdProducts.Add(item2.Product.Value);
 }
Run Code Online (Sandbox Code Playgroud)

结果是:5 6 7 5 2 5

我需要得到以下5 = 3,6 = 1,7 = 1,2 = 1

c# linq linq-to-sql

4
推荐指数
1
解决办法
260
查看次数

Length中的NullReferenceException

我有一个代码:

string[] sizes = new string[] {"1","11","2","22","200","222", null, "105", "101", "102", "103", "90" };

try
{
  var size = from x in sizes
           orderby x.Length, x
           select x;

  foreach (var p in size)
  {
     Console.WriteLine(p);
  }
   Console.Read();
}
catch (NullReferenceException)
{
}
Run Code Online (Sandbox Code Playgroud)

我如何在x.Length中捕获null,并继续执行代码?

c# linq

2
推荐指数
1
解决办法
182
查看次数

如何在linq中查询tsql

在sql我有查询

select * from table where id in (5,7,8)
Run Code Online (Sandbox Code Playgroud)

在LINQ查询中如何做到这一点?

c# sql linq

1
推荐指数
1
解决办法
66
查看次数

标签 统计

c# ×4

linq ×4

linq-to-sql ×2

sql ×1

windows ×1

winforms ×1