Click here to Skip to main content
15,921,793 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello I got this error while trying to do this

C#
 IEnumerable<operatriceviewmodel> model = null;

model=  (
             from e in db.Operatrices
             join j in db.Operations
             on e.Id_Operatrice equals j.Id_Operatrice
             select new
             {
                 Id_Operatrice = e.Id_Operatrice,
                 Nom_Operatrice = e.Nom_Operatrice,
                 Prenom_Operatrice = e.Prenom_Operatrice,
                 Designation = j.Designation
             }
         );
 return View(model);

Help me please to fix it

[Edit (MTH): cleaned-up markup]
Posted
Updated 3-Sep-14 10:52am
v2

Assuming that the properties of the anonymous type are actually the same properties the ViewModel has, just adding one word to the query should do the trick:
C#
IEnumerable<operatriceviewmodel> model = null;
 
model=  (
            from e in db.Operatrices
            join j in db.Operations
            on e.Id_Operatrice equals j.Id_Operatrice
            select new operatriceviewmodel // <--- here
            {
                Id_Operatrice = e.Id_Operatrice,
                Nom_Operatrice = e.Nom_Operatrice,
                Prenom_Operatrice = e.Prenom_Operatrice,
                Designation = j.Designation
            }
        );
return View(model);
 
Share this answer
 
Comments
Member 11017618 3-Sep-14 20:28pm    
It worked !! THANK YOU A LOT
Sergey Alexandrovich Kryukov 3-Sep-14 20:47pm    
5ed.
—SA
Member 11017618 5-Sep-14 15:49pm    
I have another problem if I may

when i generate the view this is what shows


Id_Operatrice Designation
2 //List of Operation.Designation
2
2
2

I want it do be only one row for each Operatrice

do you have an idea how to fix it ? thank you
The problem is that the result of the select is IQueryable<AnonymousType#1> but the model is IEnumerable<operatriceviewmodel>.
Either:
change the type of the model to the non-generic IEnumerable or
use var model = ( from ... select ...) or
change the select to return operatriceviewmodel values.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900