32 lines
1.2 KiB
C#
32 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using FluentNHibernate.Conventions;
|
|
using FluentNHibernate.Conventions.AcceptanceCriteria;
|
|
using FluentNHibernate.Conventions.Inspections;
|
|
using FluentNHibernate.Conventions.Instances;
|
|
using Taloyhtio.GeneralSSO.Server.CodeFiles.Entities;
|
|
|
|
namespace Taloyhtio.GeneralSSO.Server.CodeFiles.Infrastructure.DataAccess
|
|
{
|
|
// This convention is needed for storing enum as integer in database (by default enums are mapped to strings in nh)
|
|
public class EnumConvention : IUserTypeConvention
|
|
{
|
|
public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
|
|
{
|
|
criteria.Expect(x => x.Property.DeclaringType != typeof(Log) &&
|
|
(x.Property.PropertyType.IsEnum ||
|
|
(x.Property.PropertyType.IsGenericType &&
|
|
x.Property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>) &&
|
|
x.Property.PropertyType.GetGenericArguments()[0].IsEnum)
|
|
));
|
|
}
|
|
|
|
public void Apply(IPropertyInstance target)
|
|
{
|
|
target.CustomType(target.Property.PropertyType);
|
|
}
|
|
}
|
|
}
|