This is similar to my previous post where I am trying to resolve the issue of setting up a class then a collection of the class. But I am not calling it a List<class> but as a collection that inherits from that class.
It seems to work except when it actually assigns the collection.
I get this error:
{"Unable to cast object of type 'System.Collections.Generic.List`1[BusinessLayer.DotNetType]' to type 'BusinessLayer.DotNetTypeCollection'."}
The classes are:
Then I call it like this from my code:
public DotNetTypeCollection dntcol { get; set; }
public DotNetTypeCollection dntcol2 { get; set; }
...
dntcol = new DotNetTypeCollection();
dntcol2 = dntcol.GetTypes();
the assignment to dntcol2 causes the error.
Thanks,
Tom
It seems to work except when it actually assigns the collection.
I get this error:
{"Unable to cast object of type 'System.Collections.Generic.List`1[BusinessLayer.DotNetType]' to type 'BusinessLayer.DotNetTypeCollection'."}
The classes are:
Code:
public class DotNetType
{
public string DatabaseDataType { get; set; }
public string DotNetDataType { get; set; }
}
public class DotNetTypeCollection : List<DotNetType>
{
public DotNetTypeCollection()
{
}
public DotNetTypeCollection GetTypes()
{
DbObject dbo = new DbObject();
DataSet ds = null;
ds = dbo.GetDataSet("dbGen.GetDotNetDataTypes");
return (DotNetTypeCollection)ds.Tables[0].AsEnumerable().Select(row => new DotNetType
{
DotNetDataType = row.Field<string>("DotNetDataType"),
DatabaseDataType = row.Field<string>("DatabaseDataType")
}).ToList();
}
}
Then I call it like this from my code:
public DotNetTypeCollection dntcol { get; set; }
public DotNetTypeCollection dntcol2 { get; set; }
...
dntcol = new DotNetTypeCollection();
dntcol2 = dntcol.GetTypes();
the assignment to dntcol2 causes the error.
Thanks,
Tom