Skip to content

Commit

Permalink
Legacy review of NHibernate custom mappings sample (#6932)
Browse files Browse the repository at this point in the history
  • Loading branch information
SzymonPobiega authored Dec 18, 2024
1 parent 20109f4 commit 6adef7c
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using NServiceBus;

#pragma warning disable NSB0012 // Saga data classes should inherit ContainSagaData
#region AttributesMapping

[Class]
public class OrderSagaDataAttributes :
Expand Down Expand Up @@ -45,4 +46,5 @@ public class AmountInfo
}
}

#pragma warning restore NSB0012 // Saga data classes should inherit ContainSagaData
#endregion
#pragma warning restore NSB0012 // Saga data classes should inherit ContainSagaData
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using FluentNHibernate.Mapping;

#region FluentMapping

public class OrderSagaDataFluentMap :
ClassMap<OrderSagaDataFluent>
{
Expand All @@ -26,4 +28,6 @@ public OrderSagaDataFluentMap()
c.Map(x => x.Currency).Length(3).CustomType("AnsiString");
});
}
}
}

#endregion
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;

#region LoquaciousMapping

public class OrderSagaDataLoquaciousMap :
ClassMapping<OrderSagaDataLoquacious>
{
Expand Down Expand Up @@ -40,6 +42,8 @@ public OrderSagaDataLoquaciousMap()
}
}

#endregion

public class OrderSagaDataLoquaciousLocationMap :
ClassMapping<OrderSagaDataLoquacious.Location>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using NServiceBus;

#pragma warning disable NSB0012 // Saga data classes should inherit ContainSagaData
#region AttributesMapping

[Class]
public class OrderSagaDataAttributes :
Expand Down Expand Up @@ -45,4 +46,5 @@ public class AmountInfo
}
}

#pragma warning restore NSB0012 // Saga data classes should inherit ContainSagaData
#endregion
#pragma warning restore NSB0012 // Saga data classes should inherit ContainSagaData
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using FluentNHibernate.Mapping;

#region FluentMapping

public class OrderSagaDataFluentMap :
ClassMap<OrderSagaDataFluent>
{
Expand All @@ -26,4 +28,6 @@ public OrderSagaDataFluentMap()
c.Map(x => x.Currency).Length(3).CustomType("AnsiString");
});
}
}
}

#endregion
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;

#region LoquaciousMapping

public class OrderSagaDataLoquaciousMap :
ClassMapping<OrderSagaDataLoquacious>
{
Expand Down Expand Up @@ -40,6 +42,8 @@ public OrderSagaDataLoquaciousMap()
}
}

#endregion

public class OrderSagaDataLoquaciousLocationMap :
ClassMapping<OrderSagaDataLoquacious.Location>
{
Expand Down
22 changes: 20 additions & 2 deletions samples/nhibernate/custom-mappings/sample.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ Using NHibernate mapping files is the native way to customize the mappings. The

For more information, see: [how to create a simple NHibernate based application](https://nhibernate.info/doc/tutorials/first-nh-app/your-first-nhibernate-based-application.html).

### The Mapping
### Mapping

The `.hbm.xml` contents is as follows

snippet: hmlxml

### Reading the mapping file
### Configuration

Create a custom NHibernate configuration object and use the following example to add mappings from the file system.

Expand All @@ -60,6 +60,12 @@ To use it with NServiceBus:
* or by creating a new Configuration instance and pass it to FluentNHibernate
1. Pass it to the NServiceBus NHibernate configuration.

### Mapping

snippet: FluentMapping

### Configuration

Example of a possible implementation:

snippet: FluentConfiguration
Expand All @@ -75,6 +81,12 @@ NHibernate.Mapping.Attributes needs to know what types to scan to generate an NH
1. Initialize the attribute mapping (see sample below).
1. Pass it to the NServiceBus NHibernate configuration.

### Mapping

snippet: AttributesMapping

### Configuration

Initialize the NHibernate attribute based mappings:

snippet: AttributesConfiguration
Expand All @@ -89,6 +101,12 @@ To use it:
1. Use either the model mapping or convention mapping features.
1. Pass it to the NServiceBus NHibernate configuration.

### Mapping

snippet: LoquaciousMapping

### Configuration

Initialize NHibernate Loquacious configuration:

snippet: LoquaciousConfiguration

0 comments on commit 6adef7c

Please sign in to comment.