实体框架中的查询

时间:2011-06-01 12:34:47

标签: entity-framework

在上面的查询中它给出了错误我想获取顶级记录并存储在一些字符串变量的查询列中,如字符串s = zipcd.zipcode

var zipcd = (from u in db.ZipCodes1
                                         where u.CityName == temparray[0].Trim() && u.StateAbbr == temparray[1].Trim() && u.CityType == "D"
                                         select new Viewsearch
                                         {
                                             Zipcode = u.ZIPCode,
                                             CityName = u.CityName,
                                             stateabbr = u.StateAbbr

                                         }).First();
                            Viewsearch vs = (Viewsearch)zipcd;
                            string description = (new ObservableCollection<Viewsearch>(zipcd))[0].Zipcode.ToString();


                        locationarray = vs.Zipcode + " " + vs.CityName + ", " + vs.stateabbr;

1 个答案:

答案 0 :(得分:0)

var city = temparray[0].Trim();
var stat = temparray[1].Trim();
var zipcd = db.ZipCodes1
  .Where(u => u.CityName == city && u.StateAbbr == stat && u.CityType == "D")
  .Select(new Viewsearch { Zipcode = u.ZIPCode, u.CityName, stateabbr = u.StateAbbr })
  .First();
locationarray = zipcd.Zipcode + " " + zipcd.CityName + ", " + zipcd.stateabbr;

这应该有用。