Say I have a big model with 4 models in it: m1, m2, m3, m4
I use a big model because my view needs all of them but only one model can de declared. Hence I declare the big model in mu view
I want to perform a join query on the data returned by m1 and m2; but I also want to return the result of this join query to my view
How can I do this?
Can i declare a model whose values will be that of the join query? How do I do that?
Thanks
EDIT
Say I have this, (from Yasser’s example)
public class MyMainModel {
public Students Student { get; set; }
public Cars Cars { get; set; }
public Houses house {get; set;}
}
public class Students {
public int StudentNo { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
public class Houses{
public int StudentNo {get; set;}
public string houseName {get; set;}
}
public class Cars {
public int CarNo { get; set; }
public string Name { get; set; }
public string Make { get; set; }
}
I want my main model, MyMainModel to have the car model and a model displaying student names and house names. A model like
public class ModelFromOtherModels{
public int StudentNo {get; set;}
public string HouseName {get; set;}
}
That means I have to perform a Join query on the Student and Houses model. Somthing like
from s in Student
JOIN h in Houses ON h.StudentNo = s.Student No
Select new{
StudentName = s.name,
HouseName = h.houseName
}
So that at the end, MyMainModel will be
public class MyMainModel {
public ModelFromOtherModels newModel { get; set; }
public Cars Cars { get; set; }
}
How can I do this?
It is a little difficult to understand what you ask here, but here goes my try…
Consider your model to be as shown below, where M1 is the Students class and M2 is the Cars class.
Here MyMainModel is a class which now holds these two classes together. Now the rest depends on what you mean by
join query?You said
Yes you can perform joins using LINQ.
Below are few links that I found, see if they help you