我正在使用實體框架來訪問數據庫並試圖在產品類中使用我的productModel類。但一些如何獲得轉換類型的錯誤。無法隱式轉換類型錯誤
錯誤:無法隱式轉換類型 'SporLife.Product' 到 'SporLife.Pages.Product'
這是我ManageProduct類
namespace SporLife.Pages.Management
{
public partial class ManageProduct : System.Web.UI.Page
{
private void FillPage(int id)
{
//set selected product from DB
ProductModel model = new ProductModel();
Product product = model.GetProduct(id);//error appears here
//Fill textBoxes
txtDescription.Text = product.Description;
txtName.Text = product.Name;
txtPrice.Text = product.Price.ToString();
}}}
這是我的產品型號類
namespace SporLife.Models
{
public class ProductModel
{
public Product GetProduct(int id)
{
try
{
using (SporLifeDBEntities2 db = new SporLifeDBEntities2())
{
Product product = db.Products.First(i => i.ID == id);
return product;
}
}
catch (Exception e)
{
return null;
}
}}}
SporLife.Pages.Product產物= SporLife.Models.ProductModel.GetProduct(ID); //這是課程的延伸。 –
哪個產品做'db.Products' int GetProduct(int id)'方法返回? –