I am new to Entity Framework but im trying to model my code after some examples I have found online. I thought I had it set up the way I wanted but the Query that is created is pointing to the the wrong, non-existant table. I am wondering where it got the table name because it is wrong and I am not seeing any where in any of the project files that this wrong table name was specified. Here is the query that was generated and I got from debugging:
{SELECT
[Extent1].[AssetTag] AS [AssetTag],
[Extent1].[Location] AS [Location],
[Extent1].[PoolType] AS [PoolType],
[Extent1].[InventoryStatus] AS [InventoryStatus],
[Extent1].[InventoryType] AS [InventoryType],
[Extent1].[Comments] AS [Comments]
FROM [dbo].[ComputerInventories] AS [Extent1]}
ComputerInventories should be ComputerInventory.
Here is my data model
public class ComputerInventory
{
[Key]
public String AssetTag {get; set;}
public String Location { get; set; }
public String PoolType { get; set; }
//public String ReasonInProgram { get; set; }
public String InventoryStatus { get; set; }
public String InventoryType { get; set; }
[StringLength(500)]
public String Comments { get; set; }
//public String Clock { get; set; }
}
public class AssetDBContext : DbContext
{
public DbSet<ComputerInventory> ComputerInventory { get; set; }
public AssetDBContext()
: base("Name=<name>")
{
}
}
Here here is where the I am trying to get the list from the query
public ViewResult Index()
{
return View(db.ComputerInventory.ToList());
}
I am completely lost as to where it is getting the ComputerInventories value for the table name.
Entity Framework uses naming conventions for many things. One of them is that table names are created by taking the plural of the entity name. You can remove that convention like this:
See PluralizalingTableNameConvention on MSDN.
For more information on conventions
http://entityframework.codeplex.com/wikipage?title=Custom%20Conventions