I am new in ASP.NET MVC 4; Using DATABASE FIRST APPROACH. According to my question I am using SQL stored procedure to retrieve data to populate my jQgrid. But it is retrieving all BO tables data except OrgName which is coming from Org table(look in stored procedure). So What I do to get OrgName???
My Stored Procedure is as follows :
ALTER PROCEDURE [dbo].[GetBODetails]
AS
BEGIN
SELECT b.Id, b.OrgId, b.Code, b.Name, o.Name AS OrgName
FROM Org AS o INNER JOIN BO AS b ON o.Id = b.OrgId
END
Columns of BO table :
Id = GUID
Code = NVARCHAR(50)
Name = NVARCHAR(50)
OrgId = Foreign Key ref from Org table Id
Columns of BO table :
Id = GUID
Name = NVARCHAR(50)
Used this Procedure in my MVC project by doing "Add Function Import" from Model Browser window ;by referring this article Click here. While doing this I select Returns a collection of Entities is BO model.
Model generated of BO and Org are as follows :
BO.cs
public partial class BO
{
public System.Guid Id { get; set; }
public string Code { get; set; }
public string Name { get; set; }
public System.Guid OrgId { get; set; }
public virtual Org Org { get; set; }
}
Org.cs
public partial class Org
{
public Org()
{
this.BOes = new HashSet<BO>();
}
public System.Guid Id { get; set; }
public string Name { get; set; }
public virtual ICollection<BO> BOes { get; set; }
}
Controller's code to execute Stored Procedure :
private iregEntities m_oDbCont = new iregEntities();
// GET: /BO/
public JsonResult BOGrid()
{
m_oDbCont.Configuration.ProxyCreationEnabled = false;
var BOList = m_oDbCont.GetBODetails().ToList(); // Executing stored procedure
var JsonBOList = new
{
rows = (
from BOData in BOList
select new
{
id = BOData.Id.ToString(),
cell = new string[] { BOData.OrgId.ToString(), BOData.Code, BOData.Name }
}).ToArray()
};
return Json(JsonBOList, JsonRequestBehavior.AllowGet); returning data into JSON format
}
protected override void Dispose(bool disposing)
{
m_oDbCont.Dispose();
base.Dispose(disposing);
}