日期:2014-05-17  浏览次数:20359 次

asp.net 使用列表的MAX函数获取列表id最大值问题
 Entity.WeatherMsg wm = new Entity.WeatherMsg();
                    id = (Convert.ToInt32(SeatCommon.EntitySingleton.Instance.WeatherMsgList.Max(a => a.ID)) + 1).ToString();
                    wm.ID = id;
                    wm.AirportNo = airportNo;
                    wm.Type = type;
                    wm.Msg = msg;
                    wm.Time = time;
                    wm.Addr = addr;
                    SeatCommon.EntitySingleton.Instance.WeatherMsgList.Add(wm);

获取列表中id最大值然后加1,赋给新添加的数据的id字段,但是当数据为10的时候,所获取的值加1以后就都变成10了,最后列表中的数据id除了1-9剩下全是10,为什么呢?有没有大虾知道的,请求指导啊
asp.net 列表MAX

------解决方案--------------------
你获取到的ID始终是9,所以你的ID就都是10了!你逻辑问题!代码没写好!
------解决方案--------------------
不懂 帮顶
------解决方案--------------------
引用:
 Entity.WeatherMsg wm = new Entity.WeatherMsg();
                    id = (Convert.ToInt32(SeatCommon.EntitySingleton.Instance.WeatherMsgList.Max(a => a.ID)) + 1).ToString();
                    wm.ID = id;
                    wm.AirportNo = airportNo;
                    wm.Type = type;
                    wm.Msg = msg;
                    wm.Time = time;
                    wm.Addr = addr;
                    SeatCommon.EntitySingleton.Instance.WeatherMsgList.Add(wm);