Trying to learn Linq to EF in MVC3 project...
Many to many relationship in Entity Framework:
Shirt ShirtType Type
----------- ------------- ---------
ShirtID ShirtID TypeID
ShirtName TypeID TypeName
ShirtPrice
No other fields in ShirtType maping table so now I've got navigation properties in both entities Shirt.Type and Type.Shirt.
Before generating entities from database i've created complex PK in ShirtType including both foreign keys.
I've populated the database with values.
Here's the code which i used to query the database in order to return shirts that are referenced with type Type.Name==tName
public ActionResult Browse(string tName)
{
using (TShopEntities db=new TShopEntities())
{
var typeModel = from s in db.Shirt
from t in s.Type
where t.TypeName == tName
select new tsStore.ModelView.ShirtView()
{
ShirtName=s.ShirtName,
ShirtPrice=s.ShirtPrice
};
return View(typeModel.ToList());
}
}
My linq query returns nothing and the view prints just headers. I'm stuck here for a while now, is the linq query wrong or should i look for some other error?