I followed the example on scottgu's blog about EF code first CTP5 but I get the error that
System.Data.SqlClient.SqlException: Invalid object name 'dbo.Products'.
this is the code I got.
<add name="CTP5Context"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|EFCTP5.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
public class CTP5Context : DbContext
{
public DbSet<Product> Products { get; set; }
}
public class Product
{
public int Id { get; set; }
public string ProductName { get; set; }
public int Amount { get; set; }
}
var context = new CTP5Context();
var products = context.Products;
return View(products);
im kinda clueless here I done the same as the blogpost, its not my first time with EF (But CTP5 tho), I'm I overlooking something?
If your table name is Product in the database, try this:
[Table("Product", SchemaName = "dbo")]
public class Product
{
public int Id { get; set; }
public string ProductName { get; set; }
public int Amount { get; set; }
}
To use the Table
attribute You will need to add the following using statement:
using System.ComponentModel.DataAnnotations;
Hope this helps! It worked for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With