Archive for August 2015

LINQ Queries examples

//Model Table

 public partial class Tbl_ProductCategories
    {
        public Tbl_ProductCategories()
        {
             this.Tbl_products = new HashSet<Tbl_products>();
        }
   
        public long CId { get; set; }
        public string category { get; set; }
        public string stat { get; set; }
   
     }

//Data table object

 public class CategoriesDTO
    {
        public long CID { get; set; }
        public string Category { get; set; }
        public string image { get; set; }

    }


 //Get all categories which are active in state

 //Get all categories which are active in state
        public IQueryable<CategoriesDTO> GetAllCategories()
        {
            var categories = from b in db.Tbl_ProductCategories.Where(x => x.stat == "A")
                             select new CategoriesDTO()
                             {
                                 CID = b.CId,
                                 Category = b.category
                             };
            return categories;
        }


//Get sub categories based on category id and status is active

var subcategories = from b in db.Tbl_ProductSubCategories.Where(x => x.CId == cid && x.stat=="A")
                                select new SubCategoryDTO()
                                {

                                    SCID = b.SCId,
                                    SubCategory = b.SubCategory

                                };


Saturday, 29 August 2015
Posted by Sudhir Chekuri
Tag :

Followers

Total Pageviews

Powered by Blogger.

- Copyright © 2013 DevStudent - Metrominimalist - Powered by Blogger - Designed by Johanes Djogan -