get count from Iqueryable<T> in linq-to-sql?

Posted by Pandiya Chendur on Stack Overflow See other posts from Stack Overflow or by Pandiya Chendur
Published on 2010-05-04T11:27:05Z Indexed on 2010/05/04 11:38 UTC
Read the original article Hit count: 209

The following code doesn't seem to get the correct count.....

 var materials = consRepository.FindAllMaterials().AsQueryable();
 int count = materials.Count();

Is it the way to do it.... Here is my repository which fetches records...

public IQueryable<MaterialsObj> FindAllMaterials()
        {
           var materials =  from m in db.Materials
            join Mt in db.MeasurementTypes on m.MeasurementTypeId equals Mt.Id
                   where m.Is_Deleted == 0
                   select new MaterialsObj()
                   {
                       Id = Convert.ToInt64(m.Mat_id),
                       Mat_Name = m.Mat_Name,
                       Mes_Name = Mt.Name,
                   };
            return materials;

        }

© Stack Overflow or respective owner

Related posts about linq-to-sql

Related posts about iqueryable