Skip to content
This repository has been archived by the owner on Dec 24, 2022. It is now read-only.

Commit

Permalink
Use EnumConverter definition for creating enum properties
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Nov 18, 2016
1 parent fd8cc1d commit 9373ef2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/ServiceStack.OrmLite/OrmLiteDialectProviderBase.cs
Expand Up @@ -142,8 +142,10 @@ public string GetColumnTypeDefinition(Type columnType, int? fieldLength, int? sc
}

var stringConverter = columnType.IsRefType()
? (IHasColumnDefinitionLength)ReferenceTypeConverter
: ValueTypeConverter;
? ReferenceTypeConverter
: columnType.IsEnum()
? EnumConverter
: (IHasColumnDefinitionLength)ValueTypeConverter;

return stringConverter.GetColumnDefinition(fieldLength);
}
Expand Down
@@ -1,6 +1,7 @@
using NUnit.Framework;
using ServiceStack.Text;
using ServiceStack.Common.Tests.Models;
using ServiceStack.Logging;

namespace ServiceStack.OrmLite.Tests
{
Expand Down Expand Up @@ -123,5 +124,13 @@ public void Can_create_ModelWithNamedCompositeIndex_table()
}
}

[Test]
public void Can_create_CompositeIndex_with_Enum()
{
using (var db = OpenDbConnection())
{
db.DropAndCreateTable<ModelWithEnum>();
}
}
}
}
Expand Up @@ -49,4 +49,18 @@ public class ModelWithCompositeIndexOnFieldSpacesDesc
[Alias("Field WithSpace2")]
public string FieldWithSpace2 { get; set; }
}

[CompositeIndex(true, nameof(UserId), nameof(UserRole))]
public class ModelWithEnum
{
public long Id { get; set; }
public long UserId { get; set; }
public UserRoleEnum UserRole { get; set; }
}

public enum UserRoleEnum
{
User,
Admin
}
}

0 comments on commit 9373ef2

Please sign in to comment.