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