Goal:
To use entity framework with N-tier in my WPF application.
Problem:
I can’t merge the class Product from the map ProductRepository to entity framework that also has a class named Product.
When I tried solving the problem I always retrieve this error message:
Error 1 Cannot implicitly convert type
‘System.Collections.Generic.List’
to
‘System.Collections.Generic.List’ D:\Arbete\kurser\C#.NET\Labbar\Lab3\ny\MediaStore\DataAccessLibrary\ProductRepository\ProductRepository.cs 45 20 DataAccessLibrary
Just a little reminder:
I would like to the class Product to be flexible that also can be used in business and presentation layer.
namespace DataAccessLibrary.ProductRepository
{
public partial class Product
{
public Int32 ArticleNumber_id { get; set; }
public string Name { get; set; }
public decimal SalePrice { get; set; }
public decimal PurchasePrice { get; set; }
//public string Book_url { get; set; }
public Int32 ProductCategory_id { get; set; }
public Int32 Supplier_id { get; set; }
public Int32 Role_id { get; set; }
}
}
namespace DataAccessLibrary.ProductRepository
{
/// <summary>
/// Responsible for uppdating, adding, deleting, retrieving data from product list.
/// </summary>
public class Productrepository : IProductrepository
{
private List<Product> myProductList;
private MediaStoreEntities _myMediaStoreEntities = new MediaStoreEntities();
public Productrepository()
{
myProductList = new List<Product>();
}
/// <summary>
/// Retrieve all data from the product list
/// </summary>
/// <returns>A list with full of product data.</returns>
public List<Product> GetAllProductList()
{
var productListt = (from a in _myMediaStoreEntities.Products
select a).ToList();
return productListt;
//return productList;
}
}
}
Class: ProductRepository
Namespace: DataAccessLibrary.ProductRepository
/// <summary>
/// Retrieve all data from the product list
/// </summary>
/// <returns>A list with full of product data.</returns>
public List<Product> GetAllProductList()
{
var productListt = (from a in _myMediaStoreEntities.Products
select a).ToList();
return productListt;
//return productList;
}



That is because you have two
Productclasses. One inProductRepositorynamespace and second inDatabasenamespace. Both partial parts must be in the same namespace to form a single class.If you are trying to use custom POCO class (only EFv4) you must turn off automatic code generation (you didn’t because you have still .Designer.cs file under your EDMX) by removing custom tool in the designer. Then you must create custom context class derived from
ObjectContextwhich will exposeObjectSet<DataAccessLibrary.ProductRepository.Product>