In SQL Server 2008 I have a view like this:
CREATE VIEW products AS
SELECT a.ID, a.Name, b.ID as SubID, b.Name as SubName
FROM main_product as a
INNER JOIN sub_product as b on a.ID = b.mainID
This is my model:
Public class Products
{
public int ID { get; set; }
public int Name { get; set; }
public int SubID { get; set; }
public int SubName { get; set; }
}
Now how can I map my MVC3's view to the SQL Server view?
UPDATE
I tried with this:
public class PartialContext : DbContext
{
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
public DbSet<Test> Test { get; set; }
public DbSet<Products> Products { get; set; }
}
and Controller:
public class ViewController : Controller
{
private PartialContext db = new PartialContext();
//
// GET: /View/
public ViewResult Index()
{
return View(db.Products.ToList());
}
}
This effort gave me an error: "Invalid object name 'dbo.Products'."
EDIT 2
Just to clarify. I want to use both code first and database first technique. It means I want to create both database and model class manually, not through code generator or database generator
UPDATE
Problem solve. I make a mistake on naming model class
