You must Sign In to post a response.
  • Category: ASP.Net MVC

    How to get child table data in mvc using linq lamdaexpression

    hi all i have a table PO_AMS AND ITS CHILD TABLE IS PANORDER_RSPTRK so i want to bring processed date from PANORDER_RSPTRK

    below i have written code where iam wrong plz suggest me or solve if any


    var pOMS =
    db.POAMS.Where(po => po.BuyerId == pAN_USER.Userid)
    .Where(po => po.Status == id)
    .Where((po => po.Latest == 1 || po.Latest == 9))
    .Include(p => p.PAN_APPROVERGROUP)
    .Include(p => p.PAN_USER)
    .Include(p => p.PAN_USER1)
    .Include(p => p.PAN_USER2)
    .Include(p => p.PAN_UPLOAD)
    .Include(p => p.PAN_ORDRSP_TRK);

    and below if have written linq not working
    if (recResDate != null)
    {
    if (recResDate != "")
    {
    DateTime rDate = DateTime.ParseExact(recResDate, eProAppConstants.ddMMyyyy, System.Globalization.CultureInfo.InvariantCulture);
    if (!rDate.Equals(DateTime.MinValue))
    {
    // pO_AMS = pO_AMS.Where(poams => DbFunctions.TruncateTime(poams.PAN_ORDRSP_TRK) == DbFunctions.TruncateTime(rDate));
    pO_AMS = pO_AMS.Where(poams => DbFunctions.TruncateTime(PAN_ORDRSP_TRK.ProcessedDate) == DbFunctions.TruncateTime(rDate));
    }
    }
  • #769208
    You can use this code snippet for entity frame work Using Include with lambda expressions
    public static class ObjectQueryExtensions
    {
    public static ObjectQuery<T> Include<T>(this ObjectQuery<T> query, Expression<Func<T, object>> selector)
    {
    string propertyName = GetPropertyName(selector);
    return query.Include(propertyName);
    }
    private static string GetPropertyName<T>(Expression<Func<T, object>> expression)
    {
    MemberExpression memberExpr = expression.Body as MemberExpression;
    if (memberExpr == null)
    throw new ArgumentException("Expression body must be a member expression");
    return memberExpr.Member.Name;
    }
    }


  • Sign In to post your comments