Hibernate version: 1.02 self compiled
I'm getting this error:
Cannot resolve method System.Data.DataTable GetDataTableStructure() because the declaring type of the method handle Noventa.Data.CommonToAll`1[T] is generic. Explicitly provide the declaring type to GetMethodFromHandle.
I'll try to explain what is happening. My nhibernate classes derived from abstract class CommonToAll.
Contract 1:n PaymentCondition
PaymentCondition n:1 PaymentConfig
Code:
public abstract class CommonToAll<T>
{
//Some code
...
/*****PROBLEM RELATED*****/
public virtual DataTable GetDataTableStructure()
{
if (dataTableStructure != null)
return dataTableStructure;
DataTable dt = new DataTable(typeof(T).Name);
for (int i = 0; i < ArrayPropertyInfo.Length; i++)
dt.Columns.Add(ArrayPropertyInfo[i].Name, ArrayPropertyInfo[i].PropertyType);
return dt.Clone();
}
protected DataRow ToDataRow()
{
/*****PROBLEM RELATED*****/
DataRow dr = GetDataTableStructure().NewRow();
for (int i = 0; i < ArrayPropertyInfo.Length; i++)
dr[ArrayPropertyInfo[i].Name] = ArrayPropertyInfo[i].GetValue(this, null);
return dr;
}
}
public class PaymentConfig : CommonToAll<PaymentConfig>
{
public virtual System.Data.DataRow GetDataRow(string codigo)
{
return da.BuscarPeloCodigo(codigo).ToDataRow();
}
}
//Let's suppose two other classes that I have
public class PaymentCondition : CommonToAll<PaymentCondition>
public class Contract : CommonToAll<Contract>
Now how I'll use the classes.
Code:
Contract c = new Contract();
//Lazy here
IList<PaymentCondition> listPC = c.PaymentConditions;
foreach (PaymentCondition pc in listPC)
{
...
/*****PROBLEM RELATED*****/
//Accessing this condition here wil cause a error in the future.
//PaymentConfig is lazy loaded.
int id = pc.PaymentConfig.Id;
//Any attempt to access the PaymentConfig's that were loaded
//will throw an exception in the CommonToAll class.
//Just like
PaymentConfig payC = new PaymentConfig();
payC.GetById(5);
}
After all I discovered that I cannot let the method GetDataTableStructure be public virtual. It only works being private or protected. I tested with any other method in the CommonToAll class and public virtual will not work. But it just happens when I lazy load a class like explained above.
I think that is something related with lazy, cache and the inheritance with generics that I've done.
I don't know if I am clear enought because there is a specific situation to the error occurs.
Thank you