I have an ASP.NET MVC3 in C# and Razor. The architecture of the application is divided in Data Access Layer (EF classes + Repository), Service Layer, Controller, ViewModels and View.
From my Service Layer ProductServices
I call the method GetAllProducts
exposed by my Repository ProductRepository
, which has the following signature:
IQueryable<Products> GetAllProducts()
Therefore within ProductServices
I call (productRepository
is an instance of ProductRepository
):
var products = productRepository.GetAllProducts();
that populates the variable products
. Now I would like to access the name of the product ProductName
from productServices
. If I use this instruction:
var productNames = products.Select(m => m.ProductName).ToList();
I am creating coupling between ServiceLayer and the EF (bypassing the repository). That means I must add to ProductRepository
a method with signature:
IQueryable<string> GetAllProductsName()
However, since I need other product information in my application, shall I create one method in productRepository
for each field of the Product
class? Is my reasoning correct? Thanks