tags:

views:

72

answers:

0

Suppose I have

public class Product
{
    public IList<Item> Item { get; set; }
}

Now, the problem is that Item can only be loaded from some web service. It's not in the database. So as is I have the only choice to do

public class Product
{
    public IList<int> ItemIds { get; set; }
}

and then somehow load Items manually.

But I suppose there're ways to deal with this automatically. For example, maybe I can implement IUserType that inside NullSafeGet() will retrieve the Item from the web service by the Id - an int field in the database. Or some Interceptor, or what else does NHibernate offers? What's the best way to do the above?

Update: a sample with IUserType can be found here. But for my purposes I'll have to inject ItemExternalRepository somehow (DI, locator) into the IUserType. Not sure if it's a problem, but... just want to know if there're well known and accepted practices to deal with legacy/external data.

Update: the only problem I see with IUserType is that it's hard to support transactions. Suppose product has 3 items and the 2nd one failed to be saved... Now, if I roll back the ProductRepository transaction, it won't roll back the 1st saved item, because there's no support for rollbacks in IUserType as far as I can see.

Update: another solution is IClassPersister/IEntityPersister implementation.