小编Don*_*nie的帖子

如何:将所有值相加并将Linq中总数的百分比分配给sql

我有一个简单的linq查询,我正在尝试扩展,以便我可以先在VoteCount字段中汇总所有值,然后为每个被提名者我想分配被提名者收到的投票百分比.

这是代码:

              TheVoteDataContext db = new TheVoteDataContext();
    var results = from n in db.Nominees
                  join v in db.Votes on n.VoteID equals v.VoteID
                  select new
                  {
                      Name = n.Name,
                      VoteCount = v.VoteCount,
                      NomineeID = n.NomineeID,
                      VoteID = v.VoteID
                  };
Run Code Online (Sandbox Code Playgroud)

c# linq linq-to-sql

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

操作方法:使用 Linq to 对象连接三个列表

问题是地址没有输出

          using System;
          using System.Collections.Generic;
          using System.Linq;
          using System.Text;

          namespace LinqToObjects
          {
            class Program
          {
    static void Main(string[] args)
    {
        var customers = Customer.GetAllCustomers();
        var addresses = Address.GetAllAddresses();
        var addressRelations = AddressRelation.GetAllAddressRelations();

        var results = customers
                    .Join(addressRelations,
                    c => c.CustomerID,
                    ar => ar.CustomerID,
                    (c, ar) => new
                    {
                        CustomerName = c.FirstName + " " + c.LastName,
                        CustomerID = c.CustomerID,
                        AddressRelID = ar.AddressID
                    });
        var resultsJoined = results
                       .GroupJoin(addresses,
                        ar => ar.AddressRelID,
                        a => a.AddressID,
                        (ar, a) => new
                        {
                            CustomerName …
Run Code Online (Sandbox Code Playgroud)

linq linq-to-objects c#-4.0

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

标签 统计

linq ×2

c# ×1

c#-4.0 ×1

linq-to-objects ×1

linq-to-sql ×1