I have a lookup table with an Enum as primary key and when I tried to use in in a master/detail situation with a LLBLGenProDataSource I got this exception:
Invalid cast from 'System.String' to 'SD.LLBLGen.Pro.Examples.Category'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Invalid cast from 'System.String' to 'SD.LLBLGen.Pro.Examples.Category'.
Source Error:
Line 577:
Line 578: // pick first, instantiate the typeconverter
Line 579: TypeConverterAttribute attributeToUse = (TypeConverterAttribute)typeConverterAttributes[0];
Line 580: if(attributeToUse.ConverterTypeName.Length <= 0)
Line 581: {
Source File: c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\DataSource\LLBLGenProDataSourceViewBase.cs Line: 579
Stack Trace:
[InvalidCastException: Invalid cast from 'System.String' to 'SD.LLBLGen.Pro.Examples.Category'.]
System.Convert.DefaultToType(IConvertible value, Type targetType, IFormatProvider provider) +14018474
System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) +14018558
SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSourceViewBase.ConvertValueToDestinationType(Type destinationType, Object sourceValue, String fieldName) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\DataSource\LLBLGenProDataSourceViewBase.cs:579
SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSourceView.CreateRuntimeFilter() in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\DataSource\LLBLGenProDataSourceView.cs:254
SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSourceView.ProduceFilterToUse(IPredicateExpression baseFilter) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\DataSource\LLBLGenProDataSourceView.cs:851
SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSourceView.ExecuteSelectEntityCollection(Int32 pageSize, Int32 pageNumber, DataSourceSelectArguments arguments) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\DataSource\LLBLGenProDataSourceView.cs:600
SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\DataSource\LLBLGenProDataSourceView.cs:529
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +28
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +313
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +146
System.Web.UI.WebControls.FormView.EnsureDataBound() +99
System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +192
System.Web.UI.Control.EnsureChildControls() +189
System.Web.UI.Control.PreRenderRecursiveInternal() +60
System.Web.UI.Control.PreRenderRecursiveInternal() +222
System.Web.UI.Control.PreRenderRecursiveInternal() +222
System.Web.UI.Control.PreRenderRecursiveInternal() +222
System.Web.UI.Control.PreRenderRecursiveInternal() +222
System.Web.UI.Control.PreRenderRecursiveInternal() +222
System.Web.UI.Control.PreRenderRecursiveInternal() +222
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4297
To repro:
download the ASP.NET 2.0 databinding example http://www.llblgen.com/pages/secure/filestreamer.aspx?DownloadID=220
change CategoryEntity.CategoryId to an Enum e.g
public enum Category
{
Beverages = 1,
Condiments,
Confections,
Dairy,
Grains,
Meat,
Produce,
Seafood
}
regen,compile,run
navigate to /ProductsDetails.aspx
Happens with adapter/selfservicing v3.1 and v3.5