C# MVC web API multiple table selected field value display with xml

Can anyone please tell me C# MVC 5 WEBAPI multiple table selected field value will display with xml. I have five tables and it has already joined. For the time being my code will display all missy field in XML out put file. How do I display only relevant fields without any duplicate fields

This is my class file

 public class Posts 
        public  Suburb suburb { get; set; }
        public SubRegion subRegion { get; set; }
        public SubRegionDeliveryTime subRegionDeliveryTime { get; set; }
        public DeliveryTime deliveryTime { get; set; }
        public DeliveryPeriod deliveryPeriod { get; set; }

This is my API Controller source code. 

public IEnumerable<Posts> Get(int pcode, string SuburbName = "")

           using (ApplicationDbContext db = new ApplicationDbContext())

               var Location1 = (from su in db.TLCSuburb.AsEnumerable()
                                where su.name.Contains(SuburbName) ||
                                su.postcode == pcode
                                join Subr in db.TLCSubRegion on
                                su.SubRegionID equals Subr.SubregionID
                                join srdt in db.TLCSubRegionDeliveryTime on
                                Subr.SubregionID equals srdt.SubregionID
                                join DT in db.TLCDeliveryTime on
                                srdt.DeliveryTimeId equals DT.DeliveryTimeId
                                join DP in db.TLCDeliveryPeriod on
                                DT.DeliveryPeriodID equals DP.DeliveryPeriodID
                                orderby Subr.SubregionID
                                select new Posts
                                    suburb = new Suburb()
                                        name = su.name,
                                        postcode = su.postcode,
                                        AuState = su.AuState,
                                        Latitude = su.Latitude,
                                        Longitude = su.Longitude
                                          //deliveryTime = DT.DeliveryDay,

                                          deliveryTime = new DeliveryTime()

                                              DeliveryDay = DT.DeliveryDay,

                                          deliveryPeriod = new DeliveryPeriod()
                                               PeriodType = DP.PeriodType

                                          subRegion = new SubRegion()
                                              CloseDayId = Subr.CloseDayId,
                                              SubregionName = Subr.SubregionName
               string subReName = "";
               int poscode;
               foreach (var item in Location1)
                   var aus = item.suburb.AuState;
                   poscode = item.suburb.postcode;
                   subReName = item.subRegion.SubregionName;

             var loc = Location1.ToList();
           // return null;
             return loc.ToList();


My out put should be this format only

<name>BLUES POINT</name>
<SubregionName>Sydney - Nth Shore - Lower</SubregionName>

Source: xml

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.