Enum is not supported?

Apr 27, 2012 at 12:28 PM

 

entity:

public class Note
{
    public int ID { get; set; }
    public ModifyType ModifyType { get; set; }
}

enum:

    public enum ModifyType
    {
        Normal = 0,
        New = 1,
        Edit = 2,
        Delete = 3
    }

 

then I insert a record:

 

context.Insert("Note", note).AutoMap(x => x.ID).Execute();

 

It failed.

I got an error : ModifyType has no default value.

I thought internal map is failed, so there is no value insert into ModifyType column.

then I change the code like this:

context.Insert("Note", note).Column("ModifyType", (int)note.ModifyType).AutoMap(x => x.ID).Execute();

It works.

It's terrible to cast all enum to int manually. Can you sovle this problem in the next version.

Thank you.

Apr 27, 2012 at 12:34 PM

Enums are supported for the select queries, but currently not supported for the insert and update builders. But I totally agree with you, I will fix it.

May 3, 2012 at 9:21 PM

I have just checked in a fix for this. I have not created a build yet, I will do that on Sunday.

May 4, 2012 at 2:16 AM

Great!

May 9, 2012 at 9:23 AM

The issue seems still exists...

May 11, 2012 at 12:18 AM

Hopefully this should be fixed now. I've checked in the fix + made a new release. Can you verify that it works?

May 11, 2012 at 3:48 AM

Yeah, it is OK now.

But I find that the AutoMap behavior changed.

foreach (var c in ignoreColumns)
{
    updateBuilder.AutoMap(c);
}

not equals

updateBuilder.AutoMap(ignoreColumns);

My repository method do not work now:

public virtual int UpdateIgnore(T entity, params Expression<Func<T, object>>[] ignoreColumns)
        {
            var updateBuilder = GetCurrentContext().Update<T>(_EntityType.Name, entity);

            foreach (var c in ignoreColumns)
            {
                updateBuilder.AutoMap(c);
            }
            return updateBuilder.Where(_KeyColumnName, _KeyColumnPropertyInfo.GetValue(entity, null)).Execute();
        }

It is not a big problem, I just get a little confuse about AutoMap and Column methods. when I use them together, the behavior sometimes be strange...

May 11, 2012 at 9:18 AM

The difference between AutoMap and Column is that AutoMap will automatically take all the scalar properties (int, string etc) on the entity type and internally call Column(propertyName, propertyValue) for those, while if you use the Column then you manually have to do it yourself.

Looking at your code I see that you call AutoMap multiple times, for each ignore column and thats incorrect. AutoMap should only be called once. So try this:

public virtual int UpdateIgnore(T entity, params Expression<Func<T, object>>[] ignoreColumns)
{
	var updateBuilder = GetCurrentContext().Update<T>(_EntityType.Name, entity).AutoMap(ignoreColumns);

	return updateBuilder.Where(_KeyColumnName, _KeyColumnPropertyInfo.GetValue(entity, null)).Execute();
}