Showing changes from revision #1 to #2: Added | Removed
If you haven't setup a Fluent NHibernate project before, you should checkout the GettingStarted: Introduction guide.
As mentioned in ClassMap, all mappings are done from inside the constructor of a ClassMap<T>
derived class; so baring that in mind, all examples are going to exclude the surrounding class.
// schema AddressNumber int AddressStreet varchar(100) // model public Address Address { get; set; } public class Address { public int Number { get; set; } public string Street { get; set; } } // mapping Component(x => x.Address, c => { c.Map(x => x.Number); c.Map(x => x.Street); });
In this example, the first lambda (x
) is used for specifying which property on your model is a component, and the second lambda (c
) is used for actually defining what the component is. When you're working inside the second lambda, it'sa verylot similarof the methods that are available with the ClassMap are able to be used with components.
If Classyou Map.need to have a property in your component that references it's parent, you can use the WithParentReference
method.
// model public Address Address { get; set; } public class Address { public int Number { get; set; } public string Street { get; set; } public Person Resident { get; set; } } // mapping Component(x => x.Address, c => { c.Map(x => x.Number); c.Map(x => x.Street); c.WithParentReference(x => x.Resident); });