Fluent NHibernate: displaying a nullable value-type property property as a component

How can I map a nullable value-type property as a component in NHibernate?

For instance:

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; } } public class PersonDbMap : ClassMap<Person> { public PersonDbMap() { /* This part doesn't compile! */ Component(x => x.Name, part => { part.Map(x => x.FirstName, "FirstName"); part.Map(x => x.LastName, "LastName"); } } } 
+4
source share
1 answer

Cannot display a struct as component.

You need to make it a class or implement IUserType .

+4
source

Source: https://habr.com/ru/post/1313825/


All Articles