相关疑难解决方法(0)

最佳实践:从属性中抛出异常

何时从属性getter或setter中抛出异常是否合适?什么时候不合适?为什么?关于这个主题的外部文件的链接将是有帮助的...谷歌出乎意料地少了.

.net c# properties exception

102
推荐指数
3
解决办法
4万
查看次数

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);
Run Code Online (Sandbox Code Playgroud)
protected void GetFinalResult(IQueryable<clsProfileDate> …
Run Code Online (Sandbox Code Playgroud)

linq-to-entities entity-framework-4

65
推荐指数
3
解决办法
9万
查看次数