-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Inheritance, lazy
PostPosted: Thu Jun 29, 2006 8:52 am 
Beginner
Beginner

Joined: Mon Mar 06, 2006 2:19 pm
Posts: 42
Location: Belo Horizonte, Brazil
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 29, 2006 1:19 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
Why are you using DataTable and DataRow if you're using NHibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 29, 2006 2:32 pm 
Beginner
Beginner

Joined: Mon Mar 06, 2006 2:19 pm
Posts: 42
Location: Belo Horizonte, Brazil
I use both. Sometimes I dynamically create datatables or datarows to bind with datagrids, combo's.... It's something like:

Forms <-> Control Classes <-> Persistent Classes(dll)

The persistent classes can generate datatables or datarows with some or all of it's properties.

I don't know if it is the best thing to do. Until now is going well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.