You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi @kbilsted , seems interesting. I can't even say the behavior right now, TBH, this is not tested by me. I will find look how I can support this soon. This should be not be a big change on the compilers, but I need to write more test on this one before publishing.
Will update this ticket about the progress moving forward.
public enum Gender
{
Male,
Female
}
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
[TypeMap(DbType.String)]
public Gender Gender { get; set; }
}
Question:
With you as a possible user, how would you behave this enum if we are missing a mapping? Should we save it as String, or should we save it as Enum Underlying Type?
I do not want to get influenced by outside discussions, so you might have already talked this one with somebody else. This question is targeted, and I would like to hear that. Thank you!
Hi, thanks for asking. There are a number of dimensions you have to consider
regular enums
"Flags" enums
storing enum as a number
storing enum as a string
invalid number (reading a number that does not fit an enum value (or combination in case of flags))
invalid string (reading a string from db that does not fit an enum value (or combination in case of flags))
so fill out all the cells below and you have the answer ;)
This make sense and thanks. Anyway, I had covered the following on first check-in:
regular enums - covered
"Flags" enums - covered
storing enum as a number - covered
storing enum as a string - covered
invalid number (reading a number that does not fit an enum value (or combination in case of flags)) - exception might be thrown as the Enum.ToObject() might fail.
invalid string (reading a string from db that does not fit an enum value (or combination in case of flags)) -- exception will be thrown as the Enum.Parse() will fail.
I also included the following.
Save the Enum as INT even the Property is STRING if you force the [TypeMap(DbType.Int)], or TypeMapper.Map(typeof(Gender), DbType.Int);
Consider the mapping in the "LinqExpression" like this (connection.Query(p => p.Gender == Gender.Female);) -- this is currently failing, so I cannot issue a "beta" build.
For now, I have an initial check-in and here is the Integration Tests.
I don't see, however, the test cases cover half of the combinations of the matrix, e.g. where the top horizontal values are writing and the vertical values are reading. I'd focus more on getting the matrix right before rushing to code.
Scenarios mentioned by your vertical and horizontal table is covered by the definitions below. But I need it to be tested well before I issue a new release build. The Integration Tests and Unit Tests are intact as per my expected behavior, but user behaviors are very important.
Database Table:
CREATE TABLE [dbo].[CompleteTable]
(
Id BIGINT IDENTITY(1, 1) PRIMARY
, ColumnBit BIT
, ColumnNVarChar NVARCHAR(32)
, ColumnInt INT
, ColumnBigInt BIGINT
, ColumnSmallInt SMALLINT
);
Class Properties:
namespace RepoDb.IntegrationTests.Models
{
[Map("[dbo].[CompleteTable]")]
public class EnumCompleteTable
{
public Guid SessionId { get; set; }
public BooleanValue? ColumnBit { get; set; }
public Direction ColumnNVarChar { get; set; }
public Direction? ColumnInt { get; set; }
public Direction? ColumnBigInt { get; set; }
public Direction? ColumnSmallInt { get; set; }
}
[Map("[dbo].[CompleteTable]")]
public class EnumAsIntForStringCompleteTable
{
public Guid SessionId { get; set; }
[TypeMap(DbType.Int32)]
public Direction ColumnNVarChar { get; set; }
}
[Map("[dbo].[CompleteTable]")]
public class TypeLevelMappedForStringEnumCompleteTable
{
public Guid SessionId { get; set; }
public Continent ColumnNVarChar { get; set; }
}
}
This class is being used on the Integration Tests provided above. The only behaviors to be considered are:
Invalid Number - fetch will succeed; inserts, updates, merge will succeed. But the mapping will not be intact on the class level (let us say: value is 100 in class property, but value is 1 in the DB) - this is expected as Enum.ToObject() will still work -- let me know if we need to change this scenario
Invalid String - fetch will fail; inserts, updates, merge will succeed. This is expected as Enum.Parse() will fail.
Activity
mikependon commentedon Jun 3, 2019
Hi @kbilsted , seems interesting. I can't even say the behavior right now, TBH, this is not tested by me. I will find look how I can support this soon. This should be not be a big change on the compilers, but I need to write more test on this one before publishing.
Will update this ticket about the progress moving forward.
mikependon commentedon Jun 4, 2019
Hi @kbilsted , I am about to work on this feature. RepoDb supports type mapping like below.
Existing features:
Type level:
Property Level:
So on this enum support, I can simply do it like this.
Type Level:
Property Level:
Question:
With you as a possible user, how would you behave this enum if we are missing a mapping? Should we save it as String, or should we save it as Enum Underlying Type?
I do not want to get influenced by outside discussions, so you might have already talked this one with somebody else. This question is targeted, and I would like to hear that. Thank you!
Initial support for Enumerations : document enum support #261
kbilsted commentedon Jun 6, 2019
Hi, thanks for asking. There are a number of dimensions you have to consider
regular enums
"Flags" enums
storing enum as a number
storing enum as a string
invalid number (reading a number that does not fit an enum value (or combination in case of flags))
invalid string (reading a string from db that does not fit an enum value (or combination in case of flags))
so fill out all the cells below and you have the answer ;)
mikependon commentedon Jun 6, 2019
This make sense and thanks. Anyway, I had covered the following on first check-in:
I also included the following.
For now, I have an initial check-in and here is the Integration Tests.
Link: https://github.com/mikependon/RepoDb/blob/master/RepoDb/RepoDb.Tests/RepoDb.IntegrationTests/EnumPropertyTest.cs
The #8 corresponds to Ln 100 to Ln 117 -- that is currently commented.
FYI: I have to write a few more tests for this to covered some more scenarios. But I will definitely issue a beta for you (to be able to test it).
Complete support for Enum with complete Test sets. document enum supp…
mikependon commentedon Jun 10, 2019
@kbilsted - a beta version has been introduced that includes this change. May I request for you to check it out and let me know about your feedback?
Documentation: https://repodb.readthedocs.io/en/latest/pages/enumeration.html
Test for NetFramework: https://github.com/mikependon/RepoDb/blob/master/RepoDb/RepoDb.Tests/RepoDb.IntegrationTests/EnumPropertyTest.cs
Test for NetCore: https://github.com/mikependon/RepoDb/blob/master/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/EnumPropertyTest.cs
Available At: >= v1.9.8-beta1
Package Manager Command: Install-Package RepoDb -Version 1.9.8-beta1
kbilsted commentedon Jun 10, 2019
Great stuff!
I don't see, however, the test cases cover half of the combinations of the matrix, e.g. where the top horizontal values are writing and the vertical values are reading. I'd focus more on getting the matrix right before rushing to code.
mikependon commentedon Jun 10, 2019
Scenarios mentioned by your vertical and horizontal table is covered by the definitions below. But I need it to be tested well before I issue a new release build. The Integration Tests and Unit Tests are intact as per my expected behavior, but user behaviors are very important.
Database Table:
Class Properties:
And with this Enum-level mapping:
Link: https://github.com/mikependon/RepoDb/blob/master/RepoDb/RepoDb.Tests/RepoDb.IntegrationTests/Models/EnumClasses.cs
This class is being used on the Integration Tests provided above. The only behaviors to be considered are:
mikependon commentedon Jun 27, 2019
The feature is now implemented at this library at version 1.9.8.
mikependon commentedon Aug 2, 2019
Closing this ticket now. Thanks!