Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# { newRow[row.Broker]=row.ItemValue\u NoFormat; } } } } 公共类CSM { 公共整数行号{get;set;} 公共字符串行号{get;set;} 公共字符串部分{get;set;} 公共字符串Displa_C#_Sql Server_Linq - Fatal编程技术网

C# { newRow[row.Broker]=row.ItemValue\u NoFormat; } } } } 公共类CSM { 公共整数行号{get;set;} 公共字符串行号{get;set;} 公共字符串部分{get;set;} 公共字符串Displa

C# { newRow[row.Broker]=row.ItemValue\u NoFormat; } } } } 公共类CSM { 公共整数行号{get;set;} 公共字符串行号{get;set;} 公共字符串部分{get;set;} 公共字符串Displa,c#,sql-server,linq,C#,Sql Server,Linq,{ newRow[row.Broker]=row.ItemValue\u NoFormat; } } } } 公共类CSM { 公共整数行号{get;set;} 公共字符串行号{get;set;} 公共字符串部分{get;set;} 公共字符串DisplayInCSM{get;set;} 公共字符串代理{get;set;} 公共字符串代理名称{get;set;} 公共int ItemValue_NoFormat{get;set;} 公共字符串周期{get;set;} 公共CSM(){} 公共CS

{ newRow[row.Broker]=row.ItemValue\u NoFormat; } } } } 公共类CSM { 公共整数行号{get;set;} 公共字符串行号{get;set;} 公共字符串部分{get;set;} 公共字符串DisplayInCSM{get;set;} 公共字符串代理{get;set;} 公共字符串代理名称{get;set;} 公共int ItemValue_NoFormat{get;set;} 公共字符串周期{get;set;} 公共CSM(){} 公共CSM( 整数行数, 字符串行号, 字符串部分, 字符串显示, 字符串代理, 断线游戏, int ItemValue_NoFormat, 字符串周期) { this.RowNumber=RowNumber; this.LineNumber=行号; 本节=节; this.DisplayInCSM=DisplayInCSM; this.Broker=Broker; this.BrokerName=BrokerName; this.ItemValue\u NoFormat=ItemValue\u NoFormat; 这个周期=周期; } } }
为什么不在模型中使用EF和ExecuteAWSQL?我的数据存储在xml中。我已经从xml文件填充了我的列表。现在告诉我如何使用C#LINQ pivot功能来表示代理名称将水平显示的数据。我们是否可以通过列表而不是datatable来表示数据,因为datatable很慢。你可以发布第二套代码示例和列表吗。谢谢。
pivot.Columns.Add(broker,typeof(int))代理在我的末尾是字符串。代理名称是字符串,项目值是int。
+------------+--------------+-----------+--------------+--------+-------------+--------------------+----------+
| RowNumber  |   Section    | LineItem  | DisplayInCSM | Broker | BrokerName  | ItemValue_NoFormat |  Period  |
+------------+--------------+-----------+--------------+--------+-------------+--------------------+----------+
|          1 | Operational  | NG Sales  | NGL          | CR     | Credit Suse |                200 | 2010 FYA |
|          2 | Operational  | NG Sales  | NGL          | GR     | Max 1       |                300 | 2010 FYA |
|          3 | Operational  | NG Sales  | NGL          | PX     | Morgan      |                100 | 2010 FYA |
|          4 | Operational  | NG Sales  | NGL          | WB     | Wells Fargo |                500 | 2010 FYA |
+------------+--------------+-----------+--------------+--------+-------------+--------------------+----------+
SET @SQL='SELECT *                                      
FROM                                                                              
(                      
  SELECT RowNumber,CAST(ISNULL(EarningID,0) AS INT) EarningID,    
  Section,    
  LineItem,    
  DisplayInCSM,     
  Type,     
  Broker,    
  BrokerName,     
  ItemValue_NoFormat,     
  TRIM(ISNULL(Period,'''')) Period,hierarchy,                
  from #tmpData1 WHERE TYPE<>''SHEET''                                                                      
) t                                                                              
PIVOT                                                                              
(                                                                              
 MAX(ItemValue_NoFormat)                                                                              
 FOR Broker IN ([5W], [8K], [CL], [DA], [EQ], [FA], [GS], [HM], [HQ], [JY], [KW], [ML], [MS], [MV], [SL], [UA],[WB])                                                                              
) AS P                                                                              
order by hierarchy,PeriodOrder   
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using
System.Data;

namespace ConsoleApplication
{
    class Program
    {
         static void Main(string[] args)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("RowNumber", typeof(int));
            dt.Columns.Add("Section", typeof(string));
            dt.Columns.Add("LineItem", typeof(string));
            dt.Columns.Add("DisplayInCSM", typeof(string));
            dt.Columns.Add("Broker", typeof(string));
            dt.Columns.Add("BrokerName", typeof(string));
            dt.Columns.Add("ItemValue_NoFormat", typeof(int));
            dt.Columns.Add("Period", typeof(string));

            dt.Rows.Add(new object[] {1, "Operational", "NG Sales", "NGL", "CR", "Credit Suse", 200, "2010 FYA"});
            dt.Rows.Add(new object[] {2, "Operational", "NG Sales", "NGL", "GR", "Max 1", 300, "2010 FYA"});
            dt.Rows.Add(new object[] {3, "Operational", "NG Sales", "NGL", "PX", "Morgan", 100,"2010 FYA"});
            dt.Rows.Add(new object[] {4, "Operational", "NG Sales", "NGL", "WB", "Wells Fargo", 500, "2010 FYA"});

            string[] brokers = dt.AsEnumerable().Select(x => x.Field<string>("Broker")).Distinct().OrderBy(x => x).ToArray();

            DataTable pivot = new DataTable();
            pivot.Columns.Add("Section", typeof(string));
            pivot.Columns.Add("LineItem", typeof(string));
            pivot.Columns.Add("DisplayInCSM", typeof(string));

            foreach (string broker in brokers)
            {
                pivot.Columns.Add(broker, typeof(int));
            }
            var groups = dt.AsEnumerable().GroupBy(x => new { section = x.Field<string>("Section"), lineItem = x.Field<string>("LineItem"), csm = x.Field<string>("DisplayInCSM")}).ToList();

            foreach (var group in groups)
            {
                DataRow newRow = pivot.Rows.Add();
                newRow["Section"] = group.Key.section;
                newRow["LineItem"] = group.Key.lineItem;
                newRow["DisplayInCSM"] = group.Key.csm;
                foreach (DataRow row in group)
                {
                    newRow[row.Field<string>("Broker")] = row.Field<int>("ItemValue_NoFormat");
                }
            }

            
        }

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

namespace ConsoleApplication
{
    class Program
    {
         static void Main(string[] args)
        {
            List<CSM> csms = new List<CSM>() {
                new CSM(1, "Operational", "NG Sales", "NGL", "CR", "Credit Suse", 200, "2010 FYA"),
                new CSM(2, "Operational", "NG Sales", "NGL", "GR", "Max 1", 300, "2010 FYA"),
                new CSM(3, "Operational", "NG Sales", "NGL", "PX", "Morgan", 100,"2010 FYA"),
                new CSM(4, "Operational", "NG Sales", "NGL", "WB", "Wells Fargo", 500, "2010 FYA")
            };

            string[] brokers = csms.Select(x => x.Broker).Distinct().OrderBy(x => x).ToArray();

            DataTable pivot = new DataTable();
            pivot.Columns.Add("Section", typeof(string));
            pivot.Columns.Add("LineItem", typeof(string));
            pivot.Columns.Add("DisplayInCSM", typeof(string));

            foreach (string broker in brokers)
            {
                pivot.Columns.Add(broker, typeof(int));
            }
            var groups = csms.GroupBy(x => new { section = x.Section, lineItem = x.LineNumber, csm = x.DisplayInCSM}).ToList();

            foreach (var group in groups)
            {
                DataRow newRow = pivot.Rows.Add();
                newRow["Section"] = group.Key.section;
                newRow["LineItem"] = group.Key.lineItem;
                newRow["DisplayInCSM"] = group.Key.csm;
                foreach (CSM row in group)
                {
                    newRow[row.Broker] = row.ItemValue_NoFormat;
                }
            }

            
        }

    }
    public class CSM
    {
        public int RowNumber { get;set;}
        public string LineNumber { get; set; }
        public string Section { get; set; }
        public string DisplayInCSM { get;set;}
        public string Broker { get;set;}
        public string BrokerName { get;set;}
        public int ItemValue_NoFormat { get;set;}
        public string Period{ get;set;}

        public CSM() {}
        public CSM(
            int RowNumber,
            string LineNumber,
            string Section,
            string DisplayInCSM,
            string Broker,
            string BrokerName,
            int ItemValue_NoFormat,
            string Period)
            {
                this.RowNumber = RowNumber;
                this.LineNumber = LineNumber;
                this.Section = Section;
                this.DisplayInCSM = DisplayInCSM;
                this.Broker = Broker;
                this.BrokerName = BrokerName;
                this.ItemValue_NoFormat = ItemValue_NoFormat;
                this.Period = Period;
            }
     }
}