any idea?

13 Ekim 2013 Pazar 16:12:50 UTC+3 tarihinde Oğuzhan EREN yazdı:
>
>
> 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.

Reply via email to