Need help getting this simple example to work

Posts   
 
    
BillZack
User
Posts: 3
Joined: 10-Aug-2005
# Posted on: 10-Aug-2005 20:33:56   

I am evaluating LLBLGen Pro. I also thought that I would give a demo to a .NET users group that I run. Unfortunately I can't seem to get this simple demo to run. I get the follwing error when I run it. The error is on the last step (using a predicate). It seems like I am follwing the documentation.

Trace and error:

Method Enter: DataAccessAdapterBase.FetchEntityCollection(6) Active Entity Collection Description: EntityCollection: DAL6.HelperClasses.EntityCollection. Will contain entities of type: CustomersEntity

An unhandled exception of type 'System.InvalidCastException' occurred in sd.llblgen.pro.ormsupportclasses.net11.dll

Additional information: Specified cast is not valid.


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using SD.LLBLGen.Pro.DQE.SqlServer;
using SD.LLBLGen.Pro.ORMSupportClasses;

using DAL6.DatabaseSpecific;
//using DAL6.TypedListClasses;
using DAL6.EntityClasses;
using DAL6.HelperClasses;
using DAL6.FactoryClasses;
using DAL6;
using System.Diagnostics;

namespace WindowsApp6
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
        private System.Windows.Forms.DataGrid dataGrid1;
        private System.Windows.Forms.TextBox textBox1;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null) 
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.dataGrid1 = new System.Windows.Forms.DataGrid();
            this.textBox1 = new System.Windows.Forms.TextBox();
            ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
            this.SuspendLayout();
            // 
            // dataGrid1
            // 
            this.dataGrid1.DataMember = "";
            this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
            this.dataGrid1.Location = new System.Drawing.Point(16, 16);
            this.dataGrid1.Name = "dataGrid1";
            this.dataGrid1.Size = new System.Drawing.Size(880, 264);
            this.dataGrid1.TabIndex = 0;
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(336, 312);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(232, 20);
            this.textBox1.TabIndex = 2;
            this.textBox1.Text = "textBox1";
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(912, 373);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.dataGrid1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
            this.ResumeLayout(false);

        }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new Form1());
        }

        private void Form1_Load(object sender, System.EventArgs e)
        {
            DataAccessAdapter adapter = new DataAccessAdapter();

            // Get a customer entity and bind it to a text box
            CustomersEntity customer = new CustomersEntity("CHOPS");
            adapter.FetchEntity(customer);
            textBox1.Text = customer.CompanyName;
            
            
            // Get all customers with their dependents and show in grid
            EntityCollection customers = new EntityCollection(new CustomersEntityFactory());
            adapter.FetchEntityCollection(customers, null);
            dataGrid1.DataSource= customers;


            // Get all customers where country = USA
            RelationPredicateBucket B = new RelationPredicateBucket();
            IPredicateExpression A = new PredicateExpression();

            A.Add(PredicateFactory.CompareValue(CustomersFieldIndex.Country, ComparisonOperator.Equal, "USA"));
            B.PredicateExpression.Add(A);

            adapter.FetchEntityCollection(customers, B);
            dataGrid1.DataSource= customers;            
        }
    }
}

BillZack
User
Posts: 3
Joined: 10-Aug-2005
# Posted on: 10-Aug-2005 22:05:39   

Here is more information on the problem. Bill Zack

Method Enter: DataAccessAdapterBase.FetchEntityCollection(6) Active Entity Collection Description: EntityCollection: DAL6.HelperClasses.EntityCollection. Will contain entities of type: CustomersEntity

An unhandled exception of type 'System.InvalidCastException' occurred in sd.llblgen.pro.ormsupportclasses.net11.dll

Additional information: Specified cast is not valid.


Unhandled Exception: System.InvalidCastException: Specified cast is not valid.
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.InterpretFilterBucket(IRelationPredicateBucket filterBucket, Boolean& relationsPresent, IPredicateExpression& expressionToPass)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, Int32 pageNumber, Int32 pageSize)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket)
   at WindowsApp6.Form1.Form1_Load(Object sender, EventArgs e) in c:\projects\windowsapp6\windowsapp6\form1.cs:line 135
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ContainerControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
   at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
   at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
   at System.Windows.Forms.Control.set_Visible(Boolean value)
   at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at WindowsApp6.Form1.Main() in c:\projects\windowsapp6\windowsapp6\form1.cs:line 109The program '[1580] WindowsApp6.exe' has exited with code 0 (0x0).

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 10-Aug-2005 22:09:35   

Very strange, I copied your code to a unittest, to reproduce your problem:


[Test]
public void SimpleCollectionFetch()
{
    using(DataAccessAdapter adapter = new DataAccessAdapter())
    {
        EntityCollection customers = new EntityCollection(new CustomerEntityFactory());
        adapter.FetchEntityCollection(customers, null);

        RelationPredicateBucket B = new RelationPredicateBucket();
        IPredicateExpression A = new PredicateExpression();

        A.Add(PredicateFactory.CompareValue(CustomerFieldIndex.Country, ComparisonOperator.Equal, "USA"));
        B.PredicateExpression.Add(A);

        adapter.FetchEntityCollection(customers, B);
    }
}

but this works OK. confused

Could you please check if you've perhaps referenced the .NET10.dll version of the ORMSupportclasses in your OWN program? (or in the dbspecific project) ?

There is one cast in the InterpretFilterBucket, which casts the bucket.RelationCollection (which is an IRelationCollection) to a RelationCollection, so that should always work, except when the objects are of two different dlls'...

Frans Bouma | Lead developer LLBLGen Pro
BillZack
User
Posts: 3
Joined: 10-Aug-2005
# Posted on: 10-Aug-2005 23:06:50   

That was it. I had references to the 1.0 versions in my GUI project. It works like a charm now.

Thanks, and thanks for the quick reply. Bill Zack

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 10-Aug-2005 23:14:32   

Glad it's solved! Good luck with the demo for your usergroup! simple_smile

Frans Bouma | Lead developer LLBLGen Pro