AutoMap HasOne

11 views
Skip to first unread message

Dewy

unread,
Jan 17, 2013, 8:52:34 AM1/17/13
to fluent-n...@googlegroups.com
Hi,

in the following domain:


    public class HasOneAttribute : Attribute
    {

    }

    public abstract class Entity
    {
        public virtual int Id { get; set; }
    }

    public class User : Entity
    {
        public virtual string Name { get; set; }

        [HasOne]
        public virtual Membership Membership { get; set; }
    }

    public class Membership : Entity
    {
        public virtual string Description { get; set; }

        public virtual User User { get; set; }
    }

I would like the tables created to be something like

table User
{
   Id int (PK),
   Name varchar(255)
}

table Membership
{
   Id int (PK),
   Description varchar(255),
   UserId int (FK)
}

I can do this using the class maps, but what I am really looking to do is use conventions or overrides to check for the attribute HasOneAttribute and make this a HasOne map rather than a References map.

Is there a simple way to do this?

Cheers
Anthony

Dewy

unread,
Jan 17, 2013, 8:59:27 AM1/17/13
to fluent-n...@googlegroups.com
I mean to say that I wanted to use AutoMap features if possible. I realise that I can do this with one override :

    public class UserMap : IAutoMappingOverride<User>
    {
        public void Override(AutoMapping<User> mapping)
        {
            mapping.HasOne(x => x.Membership);
        }
    }

But I want it to be generic and not have to do this if possible

Reply all
Reply to author
Forward
0 new messages