I使用实体框架4.3.1.0
SQL 2008 SQL 服务器
我有意见
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
我有实体
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 结果 强>
发牌者 1
发牌者 2
<强度 > 实体框架结果 强 >
发牌者 1
发牌者 1
控制器 < / 强 > 中的 < 强 > 代码
public ActionResult ShowProductDealers(int id)
{
var dealer = this.dealerService.GetDealerByProductId(id);
return this.PartialView("ShowProductDealers", dealer);
}
public IEnumerable<DealerViews> GetDealerByProductId(int id)
{
return this.repositoryViews.All.Where(item => item.Id == id);
}
仓库 < / 强 > 中的 < 强 > 代码
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();
}