Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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);
           //IEnumerable<PtModifer> PtModifer = new List<PtModifer>();
           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;

           };
       }
Posted
Updated 15-Oct-18 2:54am
v3

1 solution

You need to convert your output in JSON format to get your desired format string. Try with below -

c# - converting list to json format - quick and easy way - Stack Overflow[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900