I have a problem with a query that return 2 same customer record in a table,, so in my database I got a customer table, a CustomerProduct table and I got a Product table, customer can have many product.
public IPagedList<Customer> SearchCustomer(string product, string address, string county)
{
ICriteria criteria = Session.CreateCriteria<Customer>()
.CreateAlias("CustomerProducts", "cp")
.CreateAlias("cp.Product", "p");
if (!string.IsNullOrEmpty(product))
{
criteria.Add(Restrictions.Like("p.Name", product));
}
if (!string.IsNullOrEmpty(address))
{
criteria.Add(Restrictions.Like("Address1", address, MatchMode.Anywhere));
}
if (!string.IsNullOrEmpty(county))
{
criteria.Add(Restrictions.Like("County", county, MatchMode.Anywhere));
}
return criteria.Future<Customer>();
}
above query return a customer record two time, because of customer have many record!!
any thought/idea how to fix this, it will be great
thank you