use the "bool throwOnNotFound" overload of FindByPrimaryKey.
it will use NH's Load method, which does not hit the DB, but rather creates
a proxy with ID - just what you need, and you keep the OO semantics.



newBill.RecipientCompany =
ActiveRecordMediator<Company>.FindByPrimaryKey(record.RecipientCompanyId, *
true*);

On Wed, Apr 29, 2009 at 12:13 PM, Darius Damalakas <
[email protected]> wrote:

>
> I need to create some thousand of records.
>
> For each record I have selected a payerCompanyID and
> recipientCompanyId fields with HQL query (aggregation, summing, ant
> stuff).
>
> Is it possible somehow to insert into database a new Bill record
> without fetching Company from database?
>
> Now i have this:
> newBill.RecipientCompany =
> ActiveRecordMediator<Company>.FindByPrimaryKey
> (record.RecipientCompanyId);
> newBill.PayerCompany = ActiveRecordMediator<Company>.FindByPrimaryKey
> (record.PayerCompanyId);
> ActiveRecordMediator.Save(newBill)
>
>
> Instead, i would like to have this:
> newBill.RecipientCompany.Id = record.RecipientCompanyId;
> newBill.PayerCompany.Id = record.PayerCompanyId;
> ActiveRecordMediator.Save(newBill)
>
> Is it somehow possible? It should be, because if i load a bill, then
> both Company fields are not loaded, but the Id can be accessed.  So
> both companies are unitialized proxies. Maybe something liek this
> would work:
> newBill.RecipientCompany.Id = NHUtils.MakeUnitializedProxy<Company>
> (record.RecipientCompanyId);
> newBill.PayerCompany.Id =  NHUtils.MakeUnitializedProxy<Company>
> (record.PayerCompanyId);
> ActiveRecordMediator.Save(newBill)
>
> Thank you for any ideas
>
> >
>



-- 
Ken Egozi.
http://www.kenegozi.com/blog
http://www.delver.com
http://www.musicglue.com
http://www.castleproject.org
http://www.gotfriends.co.il

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" 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/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to