2011-07-29 8 views
2

2 개의 클래스가 있습니다.FluetnNhibernate의 사용자 정의 유형을 매핑하십시오.

public class Name 
{ 
    public string FirstName { get; set; } 
    public string LastName { get; set; } 
} 

class Person 
{ 
    public virtual Name Name { get; set; } 
    public virtual int Age { get; set; } 
} 

나는이 같은 데이터베이스에 사람을 매핑 할 :

| First Name | LastName | Age | 

나는 이름에 대한 IUserType 구현을 만들려고. 그러나 여기

public SqlType[] SqlTypes 
    { 
     get { return new[] { new SqlType(DbType.String), new SqlType(DbType.String) }; } 
    } 

나는 예외를 가지고

당신이 실제로 요구하는 것은 구성 요소입니다
property mapping has wrong number of columns 

답변

3

:

:

수업지도

https://github.com/jagregory/fluent-nhibernate/wiki/Fluent-mapping#componentmap의 모습

public class NameComponent : ComponentMap<Name> 
{ 
    public NameComponent() 
    { 
     Map(x => x.FirstName); 
     Map(x => x.LastName); 
    } 
} 

public class PersonMap : ClassMap<Person> 
{ 
    public PersonMap() 
    { 
     Id(x => x.Id)... 
     Map(x => x.Age); 
     Component(x => x.Name); 
    } 
} 

그러면 FirstName/LastName을 두 개의 개별 열과 동일한 사람 테이블로 매핑합니다. 하지만 하나의 Name 객체를 Person에 제공하십시오.


구성 요소를 오토해야하는 경우,이 블로그를 살펴 걸릴 :

http://jagregory.com/writings/fluent-nhibernate-auto-mapping-components/

관련 문제