tags:

views:

244

answers:

4

I use this:

   public class ConstructionRepository
    {
        private CRDataContext db = new CRDataContext();

        public IQueryable<Material> FindAllMaterials()
        {
            //return db.Materials;
            var materials = from m in db.Materials
                            join Mt in db.MeasurementTypes on m.MeasurementTypeId equals Mt.Id
                            select new Material
                            {
                                Mat_Name =  m.Mat_Name,
                                MeasurementTypeId =  Mt.Name, 
                                 Mat_Type = m.Mat_Type };
            return materials.AsQueryable();
        }
    }

It gives me the only error

  1. 'CrMVC.Models.Material' does not contain a definition for 'MatId','MesName','MesType'

EDIT: 'MatId','MesName','MesType' are just fake names i gave is that wrong..

+4  A: 

I would say that fixing the first error would be a good place to start - are you certain that you have referenced the assembly containing MaterialsView in your project and have added a using directive at the top of your code file to include the namespace for MaterialsView?

The other two errors [see edit] The first and third errors will go away once you have properly referenced and included the MaterialsView type.

Edit: As Tejs points out in his answer, the second error is definitely due to the fact that you are missing a call to AsQueryable.

Andrew Hare
@Andrew look at my edit...
Pandiya Chendur
+1  A: 

1) Make sure whatever namespace your 'MaterialsView' class is in is reference in this code file. If it is referenced, check to make sure that file is building and doesn't have any compiler errors it is throwing - sometimes it can mask the true error.

2) A LINQ query like this will return an IEnumerable instance, not an IQueryable. When you return material, call materials.AsQueryable();

3) I'm not seeing a call to ToList() in this method, where is the compiler telling you this error is occuring?

Tejs
+1 The second error is definitely because of the missing call to `AsQueryable` nice catch!
Andrew Hare
@Tejs look at my edit
Pandiya Chendur
A: 

The type or namespace name MaterialsView could not be found (are you missing a using directive or an assembly reference?)

(yes, this is an answer).

ima
You can't see this, but I'm rolling my eyes so hard right now...
Tejs
+1  A: 

The Material class must have settable properties with the same names as those used in your select new Material { ... } clause, you can't just make these up.

Daniel Renshaw
@Daniel Oh i now get the point
Pandiya Chendur