LINQ Entity Data Reader does not support enums

entity-framework enums sqlbulkcopy

Question

I decided that using the SqlBulkCopy class would be the best solution to handle my need to batch insert several things. Nevertheless, that class relies onDataReader while my code uses an IEnumerable where T is my entity class and works with instances, I discovered the following code to change my IEnumerable into a DataReader: Entity Data Reader for LINQ.

The only issue with this code is that the datareader does not have the enum attributes for my entity type (and therefore not being inserted correctly). How can I get the attributes of the enum type to be recognized?

1
5
11/15/2012 8:02:32 AM

Accepted Answer

I learned that this is because of theIsScalarType method not accounting for enums. This may be quickly resolved by changing theIsScalarType using the next approach:

private static bool IsScalarType(Type t)
{
    // The || t.IsEnum part is new and makes sure that enums are recognized
    return scalarTypes.Contains(t) || t.IsEnum;
}

Following this change, enum types will also be recognized.

4
11/15/2012 8:02:32 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow