- Home
- LLBLGen Pro
- LLBLGen Pro Runtime Framework
Using the generic type 'SD.LLBLGen.Pro.ORMSupportClasses.TypedListBase2<T>' requires '1' type arguments
Joined: 12-May-2007
I just upgraded to v2.6 (downloaded and installed today)
I removed all of my runtime references and repointed to the new version.. (.NET 2.0 / SQL Server))
The adapter project is building fine. We implimented generics and I am having a little trouble with the TypedListBase2. It is causing a build issue.. I was looking through the release notes and it mentioned that this was made generic but I am not sure how this affects my code except that it broke
Here is the build error:
Error 2 Using the generic type 'SD.LLBLGen.Pro.ORMSupportClasses.TypedListBase2<T>' requires '1' type arguments C:\projects\CDP\CDPSource\CDPAdapterServices\BaseServices.cs 298 17 GovPartner.CDPAdapterServices
protected virtual GovPartnerExecutionContext<T> FetchTypedList<T>(Type listType, IPredicateExpression filter, ISortExpression sort, int maxToReturn, eStringsRes infoMessageType, eErrorsRes errorMessageType, bool allowDuplicates) where T : TypedListBase2
{
string callingMethod = GetCallingMethodName();
NullCheck(listType, "listType", callingMethod, "GetTypedList");
try
{
TypedListBase2 typedList = Activator.CreateInstance<T>();
GovPartnerExecutionContext<T> context =
(GovPartnerExecutionContext<T>)Activator.CreateInstance(typeof(GovPartnerExecutionContext<T>), typedList);
IRelationPredicateBucket bucket = ((ITypedListLgp2)typedList).GetRelationInfo();
bucket.PredicateExpression.Add(filter);
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
adapter.FetchTypedList(((ITypedListLgp2)typedList).GetFieldsInfo(), typedList, bucket, maxToReturn, sort, allowDuplicates);
log.Debug(String.Format("{0} : {1} list successfully retrieved: {2}", callingMethod, listType.Name, typedList.Count));
AddInfoMessage(context, infoMessageType, typedList.Rows.Count.ToString());
return context;
}
}
catch (ORMQueryExecutionException err)
{
string message = String.Format("{0} : Exception while calling FetchTypedList( {1} )", callingMethod, listType.Name);
log.Fatal(message, err);
log.Fatal(String.Format("{0} : Exception Query: {1}", callingMethod, err.QueryExecuted));
throw new GPException(message, err);
}
catch (Exception ex)
{
string message =
String.Format("{0} : Exception while calling adapter.FetchTypedList {1} )", callingMethod,
listType.Name);
log.Fatal(message, ex);
throw new GPException(message, ex);
}
}
thanks in advance for having a look..
Best,
jon
Joined: 12-May-2007
That does work but when I call adapter.FetchTypedList the result is projected into a DataTable which causes this:
Error 2 Cannot convert type 'T' to 'System.Data.DataTable' C:\projects\CDP\CDPSource\CDPAdapterServices\BaseServices.cs 351 85 GovPartner.CDPAdapterServices
T typedList = Activator.CreateInstance<T>();
GovPartnerExecutionContext<T> context =
(GovPartnerExecutionContext<T>)Activator.CreateInstance(typeof(GovPartnerExecutionContext<T>), typedList);
IRelationPredicateBucket bucket = ((ITypedListLgp2)typedList).GetRelationInfo();
bucket.PredicateExpression.Add(filter);
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
adapter.FetchTypedList(((ITypedListLgp2)typedList).GetFieldsInfo(), (DataTable)typedList, bucket, maxToReturn, sort, allowDuplicates);
log.Debug(String.Format("{0} : {1} list successfully retrieved: {2}", callingMethod, listType.Name, typedList.Count));
AddInfoMessage(context, infoMessageType, typedList.Count.ToString());
return context;
}
Instead I used the Interface ITypeListLgp2 then used the (DataTable)typelist for the Data Table to fill. Seems to be working as expected. Here is the working code:
protected virtual GovPartnerExecutionContext<T> FetchTypedList<T>(Type listType, IPredicateExpression filter, ISortExpression sort, int maxToReturn, eStringsRes infoMessageType, eErrorsRes errorMessageType, bool allowDuplicates) where T : ITypedListLgp2
{
string callingMethod = GetCallingMethodName();
NullCheck(listType, "listType", callingMethod, "GetTypedList");
try
{
ITypedListLgp2 typedList = Activator.CreateInstance<T>();
GovPartnerExecutionContext<T> context =
(GovPartnerExecutionContext<T>)Activator.CreateInstance(typeof(GovPartnerExecutionContext<T>), typedList);
IRelationPredicateBucket bucket = ((ITypedListLgp2)typedList).GetRelationInfo();
bucket.PredicateExpression.Add(filter);
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
adapter.FetchTypedList(((ITypedListLgp2)typedList).GetFieldsInfo(), (DataTable)typedList, bucket, maxToReturn, sort, allowDuplicates);
log.Debug(String.Format("{0} : {1} list successfully retrieved: {2}", callingMethod, listType.Name, typedList.Count));
AddInfoMessage(context, infoMessageType, typedList.Count.ToString());
return context;
}
}
catch (ORMQueryExecutionException err)
{
string message = String.Format("{0} : Exception while calling FetchTypedList( {1} )", callingMethod, listType.Name);
log.Fatal(message, err);
log.Fatal(String.Format("{0} : Exception Query: {1}", callingMethod, err.QueryExecuted));
throw new GPException(message, err);
}
catch (Exception ex)
{
string message =
String.Format("{0} : Exception while calling adapter.FetchTypedList {1} )", callingMethod,
listType.Name);
log.Fatal(message, ex);
throw new GPException(message, ex);
}
}
Thanks again for having a look,
jon
howez wrote:
That does work but when I call adapter.FetchTypedList the result is projected into a DataTable which causes this:
Error 2 Cannot convert type 'T' to 'System.Data.DataTable' C:\projects\CDP\CDPSource\CDPAdapterServices\BaseServices.cs 351 85 GovPartner.CDPAdapterServices
That's because the where clause in the generic class definition isn't restrictive enough, it only requires ITypedListLgp2, which is always implemented on a typedlist, and therefore a datatable, however the compiler doesn't know that.
(snip) Instead I used the Interface ITypeListLgp2 then used the (DataTable)typelist for the Data Table to fill. Seems to be working as expected.
It's indeed often more easier to work with the interface interfaces are a different kind of generic programming, where you don't have to worry about generic type arguments, which iare often unknown and not definable due to limitations in C#'s restriction clauses...