使用LINQ查询时出现的字段顺序问题

我在使用关联表查询时,代码如下:

var q = from s in DC.PRODUCT_PLAN_BATCH

                        from c in s.PRODUCT_PLAN_ITEM

                        from i in c.WORKPLAN_CODES

                        where (strarray).Contains(i.NAME) &&

                        c.TIME_START >= dtstart &&

                        c.TIME_START <= dtend

                        orderby c.TIME_START

                        select new Info

                        {

                            批次 = s.BAT_NO,

                            阶段 = i.NAME,

                            瓶数 = (int)s.TOTAL_NUMBER,

                            培育室 = "",

                            生长室="",

                            周期 = "",

 

                            计划开始时间 = c.TIME_START,

                            计划结束时间 = c.TIME_END,

                            实际开始时间 = c.REAL_START,

                            实际结束时间 = c.REAL_END

                        };

其中Info 为我自己声明的类:

public class Info

        {

            string _批次;

            string _阶段;

            int _瓶数;

 

            string _培育室;

            string _生长室;

            string _周期;

 

            DateTime? _计划开始时间;

            DateTime? _计划结束时间;

            DateTime? _实际开始时间;

            DateTime? _实际结束时间;

 

 

          

 

            public string 培育室

            {

                get { return _培育室; }

                set { _培育室 = value; }

            }

 

 

            public string 生长室

            {

                get { return _生长室; }

                set { _生长室 = value; }

            }

 

 

            public string 周期

            {

                get { return _周期; }

                set { _周期 = value; }

            }

 

 

 

            public int 瓶数

            {

                get { return _瓶数; }

                set { _瓶数 = value; }

            }

 

            public DateTime? 计划开始时间

            {

                get { return _计划开始时间; }

                set

                {

                    if (value != null)

                    {

                        _计划开始时间 = value;

                    }

                }

            }

 

            public DateTime? 计划结束时间

            {

                get { return _计划结束时间; }

                set

                 {

                     if (value != null)

                     {

                         _计划结束时间 = value;

                     }

                 }

            }

 

            public DateTime? 实际开始时间

            {

                get { return _实际开始时间; }

                set

                {

                    if (value != null)

                    {

                        _实际开始时间 = value;

                    }

                }

            }

 

            public DateTime? 实际结束时间

            {

                get { return _实际结束时间; }

                set

                {

                    if (value != null)

                    {

                        _实际结束时间 = value;

                    }

                }

            }

 

           public string 批次

            {

                get { return _批次; }

                set { _批次 = value; }

            }

 

            public string 阶段

            {

                get { return _阶段; }

                set { _阶段 = value; }

            }

 

 

        }

 

将其绑定到datagridview上,

Datagridview.datasource = q.tolist();

后来发现datagridview的列的顺序怎么都不对,【批次】【阶段】列在最后面,最后发现datagridview中列的顺序是按照类Info中的属性顺序排列的,恍然大悟。

posted @ 2013-10-11 17:05  苗苗她爹  阅读(211)  评论(0编辑  收藏  举报