Now I want a Distinct list of Subscription Plans that are Membership Products. In SQL this works:
SELECT DISTINCT GroupId, Name
FROM ac_SubscriptionPlans
WHERE ProductId IN ( SELECT productID FROM ac_Products WHERE IsMembership = 1)
In the SubscriptionPlanRepository I created this:
Code: Select all
/// <inheritdoc />
public IList<SubscriptionPlan> LoadForMembership()
{
IList<Product> products = ProductDataSource.GetMembershipProducts();
List<int> productIds = new List<int>();
foreach (Product product in products)
{
productIds.Add(product.Id);
}
return NHibernateHelper.CreateCriteria<SubscriptionPlan>()
.SetProjection(Projections.Distinct(Projections.Property("GroupId")))
.Add(Restrictions.In("Product.Id", productIds.ToArray()))
.List<SubscriptionPlan>();
}
In SubscriptionPlan.cs I see this:
Code: Select all
/// <summary>
/// Gets or sets the Group for this entity.
/// </summary>
public virtual int GroupId
{
get { return this.Group != null ? this.Group.Id : 0; }
set { this.Group = CommerceBuilder.DomainModel.EntityLoader.Load<Group>(value); }
}