- Back to Home »
- LINQ »
- LINQ Queries examples
Posted by :
Sudhir Chekuri
Saturday, 29 August 2015
//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
};
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
};