I use Entity Framework 4.3.1.0
SQL Server 2008 Express
I have Views
SELECT dbo.Dealers.Name AS DealerName,
dbo.Dealers.LogoImage,
dbo.DealersProducts.Price,
dbo.DealersProducts.StatusType,
dbo.Products.Description,
dbo.Products.Name,
dbo.DealersProducts.DealerId,
dbo.Products.Id
FROM dbo.Dealers
INNER JOIN
dbo.DealersProducts
ON dbo.Dealers.Id = dbo.DealersProducts.DealerId
INNER JOIN
dbo.Products
ON dbo.DealersProducts.ProductId = dbo.Products.Id
and I have Entity
public class DealerViews : BasePersistentEntity
{
public int DealerId { get; set; }
public string DealerName { get; set; }
public string LogoImage { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public decimal Price { get; set; }
public int StatusType { get; set; }
}
This View I use for return dealer ho have request product. When I request SQL query in SQL Manager I gate correct result but in Entity Framework I get strange result. Examples
SQL result
Dealer 1
Dealer 2
Entity Framework result
Dealer 1
Dealer 1
Code in controller
public ActionResult ShowProductDealers(int id)
{
var dealer = this.dealerService.GetDealerByProductId(id);
return this.PartialView("ShowProductDealers", dealer);
}
Code in Service
public IEnumerable<DealerViews> GetDealerByProductId(int id)
{
return this.repositoryViews.All.Where(item => item.Id == id);
}
Code in repository
public class SGNRepository<T> where T : BasePersistentEntity
{
public readonly SGNContext<T> Context = new SGNContext<T>();
public IQueryable<T> All
{
get { return this.Context.Table; }
}
public IQueryable<T> AllIncluding(params Expression<Func<T, object>>[] includeProperties)
{
IQueryable<T> query = this.Context.Table;
return includeProperties.Aggregate(query, (current, includeProperty) => current.Include(includeProperty));
}
public T Find(int id)
{
return this.Context.Table.Find(id);
}
public void InsertOrUpdate(T item)
{
if (item.Id == default(int))
{
// New entity
this.Context.Table.Add(item);
}
else
{
// Existing entity
this.Context.Entry(item).State = EntityState.Modified;
}
this.Save();
}
public void Delete(int id)
{
var item = this.Context.Table.Find(id);
this.Context.Table.Remove(item);
this.Save();
}
private void Save()
{
this.Context.SaveChanges();
}