Hi!

I have a one-to-many association between several entities. That's also
the reason I'm not using bidirectional mapping.

Like so:

public class PriceInfo
{
  public virtual Created { get; set; }
  public decimal Amount { get; set; }
}

public class PriceInfoA : PriceInfo {}
public class PriceInfoB : PriceInfo {}

I have several subclasses of PriceInfo, because I some entities have
many lists of different PriceInfo objects.

public class Employee
{
  // ...
  public virtual ISet<PriceInfoA> PriceInfoAs { get; set; }
  public virtual ISet<PriceInfoB> PriceInfoBs { get; set; }
}

Since I have different types of entities which are using PriceInfos,
PriceInfo has no reference to "parent" entity.

I'm facing two issues here:

1) I want to query for PriceInfo items in a collection and get it back
ordered by Created field

I have a query like so:
            var employee = _session.CreateCriteria<Employee>()
                .Add(Restrictions.Eq("Id", id))
                .CreateCriteria("PriceInfoAs")
                .AddOrder(Order.Desc("Created"))
                .List<Employee>();

And this does _not_ return ordered PriceInfo objects. Obviously, I'm
missing something. How can I write this query? I'm interested only in
PriceInfoA objects, not the Employee object

2) I want to query without loading a Parent entity (Employee in this
case).

If I don't have a bidirectional association, is there any way (except
RAW SQL) to query for priceInfo objects without loading Employee
entitiy beforehand and traversing it?

Something like var priceInfo =
_session.CreateCriteria<PriceInfoA>().Add(Restrictions.Eq("Employee_id",
id)) does not work because it does not know about Employee (see the
reasons for not bidirectionally mapping above).

3) Should I model the entities differently? Note that several entities
will have same PriceInfo collections on them.

Employee -> PriceInfoA collection, PriceInfoB collection
Supplier -> PriceInfoA collection, PriceInfoB collection
etc.

Thanks for any inputs,
  Miha.

ps: the mapping I'm using (generated by FNH) contains the following
snippet (for Employee):
    <set cascade="all" name="EventHourlyRates" mutable="true">
      <key>
        <column name="Employee_id" />
      </key>
      <one-to-many class="Bbis.Models.PriceInfo, Bbis Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null" />
    </set>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to