Well, I have had this completely backwards in my head from the start and now I'm completely confused as to what I should be doing.
The database is a Number(1,0). The current T4 generated code from the EDMX is treating this as a short (Int16) so that is what I need to generate for now. The field mapping shows this as a short for the .NET type but then the target element type shows the .NET type as Boolean.
If I add relational model data directly from the database the field mapping creates a bool (and generates code for a bool).
<Field Name="Active" Type="bool" Precision="1" />
With my EDMX import, the field mapping is a short and creates a validation error so I can't generate any code unless I change it to a bool.
<Field Name="Active" Type="short" />
My question is why LLBLGen is representing this as System.Boolean based on the database type when it actually IS a short? Logically, that is correct but it's not actually what the database is. Can I create a TypeConverter to handle this? I attempted to do this but my first attempts haven't worked (code below)
My only idea for now is to change all of the fields to bool and add an attribute for [ActualType("short")] so I could handle it at generation time and turn it back into a short. That's really ugly so I'd prefer a better solution.
TypeConverter attempt
public class Int16BooleanConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType.FullName == "System.Int16";
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type sourceType)
{
return sourceType.FullName == "System.Boolean";
}
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
return Convert.ToBoolean(value) == true ? 1 : 0;
}
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
return Convert.ToInt16(value) == 1;
}
public override object CreateInstance(ITypeDescriptorContext context, System.Collections.IDictionary propertyValues)
{
return (Int16)1;
}
}