我創建了一個自定義實體創建一個強類型MVC視圖,因爲我需要填充的實體從L2S一個加入了一些數據。如何基於自定義LINQ2SQL類
當我用鼠標右鍵單擊在控制器中的「添加視圖」 ActionResult的代碼,然後選擇「創建強類型視圖」,我的課並不在選擇可用的類顯示出來。我不知道爲什麼。這裏是我的代碼:
//The Model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
namespace FurnitureStore.Models.Repository
{
public class FurnitureRepository
{
public IQueryable<Listing> GetProductListings()
{
FurnitureDataContext dc = new FurnitureDataContext();
return (from p in dc.Products
join c in dc.Categories
on p.CategoryId equals c.CategoryId
select new Listing
{
ProductName = p.ProductName,
CategoryDescription = c.CategoryDescription
});
}
}
}
//The entity class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace FurnitureStore.Models
{
public class Listing
{
public string ProductName { get; set; }
public string CategoryDescription { get; set; }
}
}
//The Method in the Controller
public ActionResult ProductListings()
{
FurnitureRepository fr = new FurnitureRepository();
var listings = fr.GetProductListings();
return View("ProductListings",listings);
}
這是解決絕對正確的方法這個! – 2011-04-05 09:09:21