I'm new to lambda expression and entity framework. My question is, I have following tables structure.
tbl_loan => loanID,LoanValue,LoanType
tbl_crin => crID,CRValue,CUSName,FacID
// here FacID is foreign key of tbl_loan(loanID)
tbl_crg => crgID,crgName,CRValue,Amount FacID
// here FacID foreign key of tbl_loan(loanID)
I need to write to take all the columns of each tables based on loanID
.how to write query using lambda expression.
In this method I need to return result of that query.which accept parameter called loanID. I tried simple one,but I have no idea to write complete code(lambda expression )
public List<tbl_loan> GetCRGDetails(int loanID)
{
var result = new List<tbl_loan>();
var entities = new LAEntities();
try
{
result = entities.tbl_loan.Where(ln => ln.loanID == loanID).ToList();
}
catch (Exception e)
{
Logger.LogWriter("SITS.SB.LA.BL.App", e, "AgeDataLogic", "GetCRGDetails");
}
return result;
}
Please help me to solve this. Here I retun tbl_loan
. should I need to create additional class to retun all the data? or have any otherway to do it?
Update:
In my project, part of details.cshtml
as follows,
@model SITS.SB.LA.DA.tbl_loan
@{
ViewBag.Title = "Details";
}
<h2>Details</h2>
<div>
<h4>Customer Loan Details</h4>
<hr/>
<label for="colFormLabelSm" class="col-sm-2 col-form-label col-form-label-sm" ng-model="">@Html.DisplayFor(model => model.ID)</label>
<label for="colFormLabelSm" class="col-sm-2 col-form-label col-form-label-sm" ng-model="">@Html.DisplayFor(model => model.NETINCOME)</label>
So, how can I display other table's columns values,such as (crID,CRValue,CUSName)
My controller class as follows,
public ActionResult Details(int id)
{
var logic = new LoanDetailsDataLogic();
var result = logic.GetCRGDetails(id);
return View(result);
}