我有一个SQL存储过程,我试图用来加载一组实体。我的实体看起来像这样
public class Person
{
public virtual int Id {get;set;}
public virtual string Name {get;set;}
public virtual Colour FavoriteColour {get;set;}
}
public class Colour
{
public virtual int Id {get;set;}
public virtual string Name {get;set;}
}
我的存储过程或多或少看起来像这样:
Create Procedure getAllPersons
AS
SELECT
p.Id as PersonId,
p.Name as PersonName,
c.Id as ColourId,
c.Name as ColourName
FROM
Person p JOIN Colour c
p.ColourId = c.Id
我的映射看起来像这样
<class name="Person">
<id name="Id">
<generator class="native"/>
</id>
<property name="Name" />
<many-to-one name="FavoriteColour" class="Foo, Colour" column="ColourId"/>
</class>
<sql-query name="getAllPersons">
<return class="Person">
<return-property name="Id" column="PersonId"/>
<return-property name="Name" column="PersonName"/>
<return-property name="FavoriteColour">
<return-column name="ColourId"/>
</return-property>
</return>
exec getAllPersons
</sql-query>
我想知道如何将我的proc的colourName列映射到Person实体上的FavoriteColour.Name属性,以便 Person上的FavoriteColour对象将填充其Id和Name属性。有什么想法吗?