Smooth NHIBERNATE: Mapping the Valid Value Type Attribute to Components

How to map nullable value type attributes to components in NHibernate?

For example:

public struct PersonName
{
public string FirstName {get; private set; }
public string LastName {get; private set; }

public PersonName(string firstName, string lastName)
{
FirstName = firstName;
LastName = lastName;
}
}

public class Person
{
public PersonName? Name {get; set; }
}
< br />public class PersonDbMap: ClassMap
{
public PersonDbMap()
{
/* This part doesn't compile! */
Component( x => x.Name,
part =>
{
part.Map(x => x.FirstName, "FirstName");
part.Map(x => x.LastName, "LastName");
}
}
}

It is impossible to map the structure as a component.

You need to set it as a class or implement IUserType.

For example:

public struct PersonName
{
public string FirstName {get; private set; }
public string LastName {get; private set; }

public PersonName(string firstName, string lastName)
{
FirstName = firstName;
LastName = lastName;
}
}

public class Person
{
public PersonName? Name {get; set; }
}
< br />public class PersonDbMap: ClassMap
{
public PersonDbMap()
{
/* This part doesn't compile! */
Component( x => x.Name,
part =>
{
part.Map(x => x.FirstName, "FirstName");
part.Map(x => x.LastName, "LastName");
}
}
}

It is impossible to map structures to components

You need to set it as a class or implement IUserType.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4522 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.