LINQ to Entities不支持指定的类型成员。仅支持初始值设定项,实体成员和实体导航属性
var result = (from bd in context.tblBasicDetails from pd in context.tblPersonalDetails.Where(x => x.UserId == bd.UserId).DefaultIfEmpty() from opd in context.tblOtherPersonalDetails.Where(x => x.UserId == bd.UserId).DefaultIfEmpty() select new clsProfileDate() { DOB = pd.DOB });foreach (clsProfileDate prod in result){ prod.dtDOB = !string.IsNullOrEmpty(prod.DOB) ? Convert.ToDateTime(prod.DOB) : DateTime.Today; int now = int.Parse(DateTime.Today.ToString("yyyyMMdd")); int dob = int.Parse(prod.dtDOB.ToString("yyyyMMdd")); string dif = (now - dob).ToString(); string age = "0"; if (dif.Length > 4) age = dif.Substring(0, dif.Length - 4); prod.Age = Convert.ToInt32(age);}GetFinalResult(result);
protected void GetFinalResult(IQueryable<clsProfileDate> result){ int from; bool bfrom = Int32.TryParse(ddlAgeFrom.SelectedValue, out from); int to; bool bto = Int32.TryParse(ddlAgeTo.SelectedValue, out to); result = result.AsQueryable().Where(p => p.Age >= from);}
我在这里得到一个例外:
LINQ to Entities不支持指定的类型成员“Age”。仅支持初始值设定项,实体成员和实体导航属性。
如果Age不在数据库中,则是我在clsProfileDate类中创建的属性,用于从DOB计算Age。对此有何解决方案?
慕盖茨4494581
德玛西亚99
相关分类