The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Issue on View

Last post 04-16-2008, 12:55 PM by dewacorp.alliances. 4 replies.
Sort Posts: Previous Next
  •  04-16-2008, 2:39 AM 8877

    Issue on View

    Hi all

    We used this software recently and it's being ok for table and such but for some reason it throws an error the view that I have.

    The view is very simple:

    SELECT     dbo.glb_Customers.CustomerID, dbo.glb_Customers.CustomerCode, dbo.glb_Customers.CompanyName, dbo.glb_Customers.Address, dbo.glb_Customers.Suburb,
                          dbo.glb_Customers.StateID, dbo.glb_Customers.Postcode, dbo.glb_Customers.CountryID, dbo.glb_Customers.DateCreated, dbo.glb_Customers.DateModified,
                          dbo.glb_Customers.IsActive AS CustomerIsActive, dbo.glb_Configurations.ConfigurationValue AS StateName,
                          glb_Configurations_1.ConfigurationValue AS CountryName, dbo.glb_Configurations.IsActive AS Configuration1IsActive,
                          glb_Configurations_1.IsActive AS Configuration2IsActive
    FROM         dbo.glb_Customers INNER JOIN
                          dbo.glb_Configurations AS glb_Configurations_1 ON dbo.glb_Customers.CountryID = glb_Configurations_1.ConfigurationID INNER JOIN
                          dbo.glb_Configurations ON dbo.glb_Customers.StateID = dbo.glb_Configurations.ConfigurationID

    This view is basically customer table joining into 2 configuration tables (same table - one is for countryid and the other one is stateid). No foreign key relationship on this just manually joining.

    The method that use is:

    protected GlbCustomersView GetCustomers(string criteria, string sortBy, string sortType)
            {
                try
                {
                    if (criteria != null)
                    {

                        GlbCustomersView collection = new GlbCustomersView();
                        collection.Query
                            .Select(collection.Query.CustomerID,
                                    collection.Query.CustomerCode,
                                    collection.Query.CompanyName,
                                    collection.Query.Address,
                                    collection.Query.Suburb,
                                    collection.Query.StateName,
                                    collection.Query.Postcode,
                                    collection.CountryName)
                            .Where
                            (
                                collection.Query.CustomerIsActive.Equal(true),
                                collection.Query.Or
                                (
                                    collection.Query.CustomerCode.Like("%" + criteria.Trim() + "%"),
                                    collection.Query.CompanyName.Like("%" + criteria.Trim() + "%"),
                                    collection.Query.Address.Like("%" + criteria.Trim() + "%"),
                                    collection.Query.Suburb.Like("%" + criteria.Trim() + "%"),
                                    collection.Query.StateName.Like("%" + criteria.Trim() + "%"),
                                    collection.Query.CountryName.Like("%" + criteria.Trim() + "%")
                                )
                            );
                        if (sortType.ToUpper() == "ASC")
                            collection.Query.OrderBy(sortBy, esOrderByDirection.Ascending);
                        else
                            collection.Query.OrderBy(sortBy, esOrderByDirection.Descending);   
                        collection.Query.Load();
                        return collection;
                    }
                    else
                    {
                        GlbCustomersView collection = new GlbCustomersView();
                        collection.Query
                            .Select(collection.Query.CustomerID,
                                    collection.Query.CustomerCode,
                                    collection.Query.CompanyName,
                                    collection.Query.Address,
                                    collection.Query.Suburb,
                                    collection.Query.StateName,
                                    collection.Query.Postcode,
                                    collection.Query.CountryName)
                            .Where(collection.Query.CustomerIsActive.Equal(true))
                            .OrderBy(collection.Query.CompanyName.Ascending);
                        collection.Query.Load();
                        return collection;
                    }
                }
                catch
                {
                    return null;   
                }
            }

    The error was in  collection.Query.Load(); the debug result is

    $exception {"Object reference not set to an instance of an object."} System.Exception {System.NullReferenceException}

    Any ideas? BTW I am using MyGeneration 1.3.0.3 and the latest version of ES and Microsoft SQL Server 2005.

    The setting that I used for MyGen is

    Under generated class master:
    Generate a Single File
    Metadata Class Should Ignore Schema
    Metadata Class Should Ignore Catalog
    Generate Hierarchical Model

    No Proxy/Stub config.

    Thanks

     



     

     

  •  04-16-2008, 4:37 AM 8883 in reply to 8877

    Re: Issue on View

    Your code looks fine, I don't see anything wrong at all. By the way, when posting code use the "code" button it's the last button on the right when editing, it's supports SQL, C#, VB.NET and so on. Let me ask you some questions:

    • Are you using ES2008? 
    • Have you ever queried the database through EntitySpaces?
    • In your "Catch" blog look at "collection.Query.es.LastQuery" and see if the SQL is okay.
    • Can you just do a simple Qiery.Load() with GlbCustomersView and no select, where and so on?


    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  04-16-2008, 10:54 AM 8907 in reply to 8883

    Re: Issue on View

    Hi Mike

    Here's my respond:

    1. We used this version: 2007.1.1210.0 (core). I had 2 folders is trial and the other one is Redistribution (purchased licence). Am I getting the wrong version? 
    2. Yes for accessing a table only and no problem (query, update and add).
    3. I don't think that is being run not even return the last query is.
    4. I comment out all the select etc and only like this:

    Code:
            protected GlbCustomersView GetCustomers(string criteria, string sortBy, string sortType)
            {
                try
                {
                    if (criteria != null)
                    {
    
                        GlbCustomersView collection = new GlbCustomersView();
                        //collection.Query
                        //    .Select(collection.Query.CustomerID, 
                        //            collection.Query.CustomerCode, 
                        //            collection.Query.CompanyName, 
                        //            collection.Query.Address, 
                        //            collection.Query.Suburb,
                        //            collection.Query.StateName,
                        //            collection.Query.Postcode,
                        //            collection.CountryName)
                        //    .Where
                        //    (
                        //        collection.Query.CustomerIsActive.Equal(true),
                       //         collection.Query.Or
                       //         (
                       //             collection.Query.CustomerCode.Like("%" + criteria.Trim() + "%"),
                       //             collection.Query.CompanyName.Like("%" + criteria.Trim() + "%"),
                       //             collection.Query.Address.Like("%" + criteria.Trim() + "%"),
                       //             collection.Query.Suburb.Like("%" + criteria.Trim() + "%"),
                       //             collection.Query.StateName.Like("%" + criteria.Trim() + "%"),
                       //             collection.Query.CountryName.Like("%" + criteria.Trim() + "%")
                       //         )
                       //     );
                        //if (sortType.ToUpper() == "ASC")
                        //   collection.Query.OrderBy(sortBy, esOrderByDirection.Ascending);
                        //else
                        //    collection.Query.OrderBy(sortBy, esOrderByDirection.Descending);    
                        collection.Query.Load();
                        return collection;
                    }
                    else
                    {
                        GlbCustomersView collection = new GlbCustomersView();
                        //collection.Query
                        //    .Select(collection.Query.CustomerID,
                        //            collection.Query.CustomerCode,
                        //            collection.Query.CompanyName,
                        //            collection.Query.Address,
                        //            collection.Query.Suburb,
                        //            collection.Query.StateName,
                        //            collection.Query.Postcode,
                        //            collection.Query.CountryName)
                        //    .Where(collection.Query.CustomerIsActive.Equal(true))
                        //    .OrderBy(collection.Query.CompanyName.Ascending);
                        collection.Query.Load();
                        return collection;
                    }
                }
                catch
                {
                    return null;    
                }
                
            }
    
     

    It throws an error on GlbCustomersView.cs on method below "An Entity can only hold 1 record of data" on this line: this.PopulateEntity(table);

    Code:
    protected bool OnQueryLoaded(DataTable table)
    		{
    			bool dataFound = this.PopulateEntity(table);
    
    			if (this.RowCount > 1)
    			{
    				throw new Exception("esGlbCustomersView can only hold one record of data");
    			}
    
    			return dataFound;
    		}

     

  •  04-16-2008, 11:03 AM 8908 in reply to 8907

    Re: Issue on View

    Are you perhps using an entity when you mean to use a collection? Try making

     

    Code:
    GlbCustomersView collection = new GlbCustomersView();

     

     

    Code:
    GlbCustomersViewCollection collection = new GlbCustomersViewCollection();
     
    Regards,

    Scott Schecter
    EntitySpaces | My Site
  •  04-16-2008, 12:55 PM 8910 in reply to 8908

    Re: Issue on View

    Hi Scott

    Well spot on. Don't realise that the view has a collection as well. :> Thank you so much.

    In regards to setting up with MyGen 1.3.0.3, is the default setting for Generated Class Master:

    Generate a Single File (tick)
    Metadata Class should ignore Schema (tick)
    Metadata Class should ignore catalog (tick)
    Generate Hierarchical Model (tick)

    It's slightly different with the one in Quick 1-2-3 document though.

    Thanks again.

     

     

     

     

     

View as RSS news feed in XML