开发者

Type or namespace name could not be found

I use this:

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

        public IQ开发者_开发技巧ueryable<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..


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.


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.


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?


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜