0

I have an old table with the following structure:

UserId GUID
SelectionId GUID 
DateSelected DATETIME

It would be easy to map it to a single class, but I would like to map it to two classes since I'm always queuing this table by the UserId

public class User
{
    Guid UserId {get;set;}
    IEnumerable<UserSelection> UserSelection {get;set;}
}

public class UserSelection
{
    public Guid SelectionId { get; set;}
    public DateTime DateSelected { get; set;}
}

I this possible in NHibernate?

Cœur
  • 37,241
  • 25
  • 195
  • 267
paddingtonMike
  • 1,441
  • 1
  • 21
  • 37

1 Answers1

0

I have not tried, but you can use mapping to a query using subselect feature, will be something like this:

public class UserMap : ClassMap<User>
{
    public UserMap()
    {
        Subselect("SELECT DISTINCT UserId FROM OldTable");

        ReadOnly();

        Id(x => x.UserId);

        HasMany(x => x.UserSelection).Table("OldTable").KeyColumn("UserId");
    }
}

public class UserSelectionMap : ClassMap<UserSelection>
{
    public UserSelectionMap()
    {
        Table("OldTable");

        Id(x => x.SelectionId);

        Map(x => x.DateSelected);

        References(x => x.User).Column("UserId").Not.Nullable();
    }
}
Community
  • 1
  • 1
Najera
  • 2,869
  • 3
  • 28
  • 52