0

我如何能够用两列非键映射另一个对象内部的对象?

public class Car
{
    public virtual int Id { get; set; }
    public virtual int AccountId { get; set; }
}

public class UserAccount
{
    public virtual int Id { get; set; }
    public virtual int UserId{ get; set; }
    public virtual int AccountId { get; set; }
}

public class User
{
    public virtual int Id { get; set; }
    public virtual int Name { get; set; }
}

假设我想获得所有用户名为“joe”的汽车。我将如何使用流利的 nhibernate 映射/查询这些?

    public Car()
    {
        Table("Car");
        Id(x => x.Id).Column("ID").GeneratedBy.Native();
        Map(x => x.AccountId);
        References(x => x.Account); // ?? needs to map accountid with the Account.Id...
    }
4

1 回答 1

0

如果要映射引用,则需要类型,而不是键。

public class Car
{
    public virtual int Id { get; set; }
    public virtual UserAccount Account { get; set; }
}

然后你会像这样映射它

public Car()
{
    Table("Car");
    Id(x => x.Id).Column("ID").GeneratedBy.Native();
    References(x => x.Account, "AccountId");
}
于 2013-10-04T17:15:12.323 回答