Reputation: 13
New to ASP.net and MVC and everything so far has come along nicely. Got to databases today and WHAT!? I'm pretty confused, and unsure where I've gone wrong here. I'm trying to use LINQ to SQL (at least, I think I am..). Let me give you the scenario of the database to help you understand better what the code is doing.
We have three tables, Inventory, Location and Equipment. Inventory contains all the data of what is in stock, names etc. Location contains LocationID and LocationName, whilst Equipment contains EquipmentID and EquipmentName. Inventory contains both EquipmentID and LocationID too.
I want to show the Station Reference, Equipment (EquipmentID turning into EquipmentName) and Location (LocationID turning into EquipmentName).
I've got the following code:
InventoryDataContext context = new InventoryDataText();
public ActionResult Index()
{
IList<InventoryModel> inventoryList = new List<InventoryModel>();
var query = from tblInventory in context
join tblEquipment in context
on tblInventory.EquipmentID equals tblEquipment.EquipmentID
join tblLocation in context
on tblInventory.LocationID equals tblLocation.LocationID
select new InventoryModel {
InventoryID = tblInventory.InventoryID,
StationReference = tblInventory.StationReference,
EquipmentID = tblEquipment.EquipmentID,
EquipmentName = tblEquipment.EquipmentName,
LocationID = tblLocation.LocationID,
LocationName = tblLocation.LocationName
};
}
Everything seems to be fine other than one error, which is:
Could not find an implementation of the query pattern for source type 'InventoryDataContext'. 'Join' not found.
It's the first context that seems to be giving the error (var query = from tblInventory in context
).
Upvotes: 1
Views: 2390
Reputation: 46947
Your syntax is incorrect. You need to specify which table in the context to use.
var query = from inv in context.tblInventory
join eq in context.tblEquipment
on inv .EquipmentID equals eq .EquipmentID
Upvotes: 2