Creating a money type
Sometimes you will need more complex types to be stored in the database, such as currencies. In this recipe, we will show you how to implement a money type and the corresponding composite user type.
How to do it…
- Create a new class library project named
MoneyExample
. - Install the
NHibernate
package using the NuGet Package Manager Console by executing the following command:Install-Package NHibernate
- Create the following
Money
class:public struct Money : IEquatable<Money> { public decimal Amount { get; } public string Currency { get; } public Money(decimal amount, string currency) { Amount = amount; Currency = currency; } public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; return obj is Money ...
Get NHibernate 4.x Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.