O'Reilly logo

NHibernate 4.x Cookbook - Second Edition by Jason Dentler, Alexander Zaytsev, Gunnar Liljas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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…

  1. Create a new class library project named MoneyExample.
  2. Install the NHibernate package using the NuGet Package Manager Console by executing the following command:
    Install-Package NHibernate
    
  3. 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required