Could you ask for a Tennant in the account constructor and just copy it's
id? Seems that would force you to ensure that the Tennant exists by
querying for it beforehand?

Alternatively add a foreign key at the database level, then catch any
foreign key exceptions when committing the changes?
On 14 Nov 2013 06:11, "Gleb Chermennov" <thebitteren...@gmail.com> wrote:

> I'm afraid that's not an option - if your component has a FK, it's not a
> component any more, but an entity.
>
> воскресенье, 13 октября 2013 г., 17:12:50 UTC+4 пользователь Oğuzhan EREN
> написал:
>>
>>
>> Hi,
>>
>> I need map TenantId (component of Account) as Foreign Key (Tenant). Db
>> must know TenantId is primary key of Tenant. When I add new record to
>> Account, nhibernate or db must validate TenantId value exists on Tenants
>> table.
>>
>> I don't want keep Reference, only Foreign Key
>>
>> Session.Save(new Account(new TenantId("guid-of-exists-tenant"),new
>> AccountId("guid"))
>>
>>
>> public class Entity<TId>
>> {
>>     public virtual TId {get;set;}
>> }
>>
>> public class TenantId
>> {
>>     public virtual Guid Id {get;set;}
>> }
>>
>> public class Tenant
>>     : Entity<TenantId>
>> {
>>     public string Name {get;set;}
>> }
>>
>> public class AccountId
>> {
>>     public virtual Guid Id {get;set;}
>> }
>>
>> public class Account
>>     : Entity<AccountId>
>> {
>>     public Account(TenantId tenantId,AccountId accountId)
>>     {
>>         TenantId = tenantId;
>>         Id= accountId;
>>     }
>>
>>     public TenantId TenantId {get;set;}
>>     public string AccountName {get;set;}
>> }
>>
>> public class TenantMap
>> {
>>     public TenantMap()
>>     {
>>         CompositeId<TenantId>(t => t.Id).KeyProperty(x => x.Id);
>> Map(x=>x.Name);
>>     }
>> }
>>
>> public class AccountMap
>> {
>>     public AccountMap()
>>     {
>>         CompositeId<AccountId>(t => t.Id).KeyProperty(x => x.Id);
>>         Component(x=>x.TenantId,m=>{
>> m.Map(x=>x.Id).Not.Nullable();
>> });
>>         Map(x => x.AccountName).Not.Nullable();
>>     }
>> }
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Fluent NHibernate" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to fluent-nhibernate+unsubscr...@googlegroups.com.
> To post to this group, send email to fluent-nhibernate@googlegroups.com.
> Visit this group at http://groups.google.com/group/fluent-nhibernate.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fluent-nhibernate+unsubscr...@googlegroups.com.
To post to this group, send email to fluent-nhibernate@googlegroups.com.
Visit this group at http://groups.google.com/group/fluent-nhibernate.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to