i have to classes .. follows
and i am trying to get list of PtModifer inside the class PModifierGroup. how can i do this ?
public class PtModifer
{
public long ProductCode { get; set; }
public long MID { get; set; }
public long MGID { get; set; }
public string Name { get; set; }
public Nullable<decimal> Price { get; set; }
}
public class PModifierGroup
{
public long MGID { get; set; }
public string GroupName { get; set; }
public Nullable<int> IsRequired { get; set; }
public string AllowMultiple { get; set; }
public List<PtModifer> PtModifer { get; set; }
}
now i want to get record from these classes in the form of ..
{
"AllowMultiple":"1",
"GroupName":"Fries",
"IsRequired":0,
"MGID":20,
"PtModifer":[
{
"MGID":20,
"MID":56,
"Name":"Sprinkles",
"Price":0.0000,
"ProductCode":1
}
]
}
.
. how to do this in wcf
What I have tried:
i have already tried
public List<PModifierGroup> GetProductModifier(string ProCode)
{
int PCode = Convert.ToInt32(ProCode);
long GroupID = -1;
using (RestroProEntities db = new RestroProEntities())
{
var result = (from P in db.ProductsModifierGroups
join MG in db.ModifierGroups on P.MGID equals MG.MGID
where P.ProductCode == PCode
select new PModifierGroup
{
MGID = MG.MGID,
IsRequired = P.IsRequired,
AllowMultiple = P.AllowMultiple,
GroupName = MG.Name,
PtModifer = (from PM in db.ProductsModifiers
join m in db.Modifiers on PM.MID equals m.MID
where PM.ProductCode == PCode & PM.MGID==MG.MGID
select new PtModifer
{
MGID = GroupID,
MID = m.MID,
Name = m.Name,
Price = m.Price
}).ToList()
}).ToList();
return result;
};
}