Typed DataTable’s base class in VS008

I have a typed Dataset, generated by VS Designer. Resently I’ve added a new column to one of the tables, and suddently in different DLLs where the dataset was used, I’ve started to get

Error 22 The type ‘System.Data.TypedTableBase`1<T0>’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’.

 

Apparently VS 2008 changed the base class for Typed DataTables 

3.5 : public partial class SubusersDataTable : global::System.Data.TypedTableBase<SubusersRow> {

2.0: public partial class SubusersDataTable : global::System.Data.DataTable, global::System.Collections.IEnumerable {

 and you need to change all dependant assemblies to

target 3.5 framework (if not done yet) and

add a reference to assembly ‘System.Data.DataSetExtensions, Version=3.5.0.0 

 

More details about the change from http://blogs.msdn.com/vbteam/archive/2008/05/14/how-linq-to-dataset-works-in-vb-jonathan-aneja.aspx

Note that for strongly-typed Datasets you don’t need to call AsEnumerable, as they inherit from TypedTableBase(Of T) which implements IEnumerable.  This is a new type in VS2008; in VS2005 the Dataset Designer would generate code that inherited from DataTable and then explicitly implemented IEnumerable itself.

 

EnitySpaces: the same Query can be used to save multiple tables

I wanted to minimize number of calls to the database, but get back results of dynamic query for small number of columns, as well as detailed data(e.g Itinerary table and Itinerary joined with Itinerary items) .In EntitySpaces
I’ve created a where condition, filled Query and loaded detailed data, then saved the returned table to DataSet.

Then  for the same query I’ve specified distinct select columns and Load it again(When LINQ will be available, it could be done in memory without extra database call).  Different table was created, that I’ve added to the same dataset. Below is code snippet:

                VwItinerariesCollection collPendingList = new VwItinerariesCollection();
                VwItinerariesQuery queryFilter = collPendingList.Query;
                queryFilter.AddWhereConditions();//custom code
                 collPendingList.Query.Load();
                 DataTable tbl= collPendingList.ConvertToDataTable();
                tbl.TableName = ListWithDetailsTable”;   
              DataSet  itineraries = new DataSet();
                itineraries.Tables.Add(tbl);
                 queryFilter.DistinctSelectForList();//custom code
                 collPendingList.Query.Load();
                 tbl = collPendingList.ConvertToDataTable();
                 tbl.TableName = ListTable”;
                 itineraries.Tables.Add(tbl);

My EntitySpaces notes

I have a few blog posts about EntitySpaces(started from this one) , as well as my posts on their forums. I want to put them together in this article as well as the links, that I consider useful.

If you need to change name of database in config, it is recommended , when generating Business Entities, in Advanced tab to set tick to Metadata Class Should  Ignore Catalog.  

To implement join for multiple tables it is suggested to create a view that brings  joined tables. They will support  joins in a future version.
There are useful EntitySpaces Query API and Query API Samples.

Filling an EsCollection out of an ordinary DataTable not supported,but you can try

    public bool CustomPopulate(DataTable dt )
{

this.Table = dt;
this.PopulateCollection();//protected method
}
}
To Clone EntitySpaces entities - the thread suggests binary serialisation(seems not always working?) and column by column copy.
Paging and Sorting on Sql 2000 using esDataSource
The ASP.NET demo source can be downloaded using Trial version and solution GridLoader.sln located under GridLoadersASP.NETC#GridLoader folder
See also EntitySpaces DotNetNuke ASCX Admin Grid Template Suite Released
  EntitySpaces and LINQ and LINQ to SQL-Aug 2007 thread .

ASP.NET MVC Northwind Demo using Entity Spaces 


NullReferenceException in EntitySpaces_C#_ASPX.csgen template after copy template instance

I am using MyGeneration Project  to generate admin web pages using EntitySpaces Templates for ASP.NET  . Filling templates is  very time consuming, and I decided to copy  template instance for one table as a start point for other table. It didn’t save much , because it require you to do everything differently for each table anyway. And it also causes an errors.
I’ve done selections im multiple tabs, but when I Executed template instances, I’ve got errors
**ERROR*** [NullReferenceException] Object reference not set to an instance of an object.
Canceled Template execution: EntitySpaces C# ASPX Page.
 
I would prefer to see mote detailed(with full call stack) message from MyGeneration.
 Fortunately, templates are relatively  easy to Debug  , and I found that when I’ve copied template instance, foreign keys from one table were copied to another, even if they are not applicable.
Debugger showed  lookupColumns={|CountryCode|FK_tblCarHireCompanyCountries_tblRefCountryName|CountryName^|HireCompanyCode|FK_tblCarHireCompanyCountries_tblRefCarHireCompanies|ShortName}

During execution code reads the foreign key name for a table and tryes to foreign key. If the name is wrong, it returns null, which causes the NullReferenceException in the call to

 Dnp.Utils.TableRelation(table, fk);
It is relatively easy to fix code by adding not null check.but there are a few places in the code where it should be done.
For example see my changes  in bold:
 
 // Lookups section
                              IForeignKey fk = table.ForeignKeys[fkName];    
                              if(fk!=null) //mnf
                              {//mnf
                                    Dnp.Utils.TableRelation tr = new Dnp.Utils.TableRelation(table, fk);
                        %>
            this.vlnk<%=esPlugIn.PropertyName(col)%>.Text = <%=tr.LookupName%>(entity.<%=esPlugIn.PropertyName(tr.PrimaryColumns[0])%>);
            this.vlnk<%=esPlugIn.PropertyName(col)%>.NavigateUrl = Globals.ApplicationPath + “/tabid/” + TabId + “/pagename/<%=esPlugIn.Entity(tr.ForeignTable)%>/<%=esPlugIn.PropertyName(tr.ForeignColumns[0])%>/” + entity.str.<%=esPlugIn.PropertyName(tr.PrimaryColumns[0])%> + “/default.aspx”;<%
                              }//mnf
  Mike.Griffin promises  that the ASP.NET templates will be completely fixed in EntitySpaces 2008.
I’ve reported the problem on EntitySpaces forum in
 
NullReferenceException in EntitySpaces_C#_ASPX.csgen template whe…

 Related link:My notes about MyGeneration Templates.

Don’t forget add EntitySpaces operands to Where method.

In EntitySpaces  you can specify filter to load data. I’ve wrote the following code



EmployeesCollection collection = new EmployeesCollection();   
Collection.Query.LastName.Like(“A%”)   
collection.Query.Load();   


and couldn’t understand why the filter doesn’t work.


The reason is that functions similat to Like, LessThan return esWhereItem that will work only after they passed to esDynamicQuery.Where(Object[]()) method.
So the correct code must be


Dim collection As EmployeesCollection = New EmployeesCollection()  
collection.Query.Where(collection.Query.LastName.Like(“A%”))
collection.Query.Load()     

Exclude non-stringable columns in EntitySpaces templates.

In MyGeneration template for EntitySpaces (see Template: Ajax Auto Complete WebServices using EntitySpaces) I wanted to loop through all columns of the table but exclude those that can not be converted to string(e.g TimeStamp).
It’s can be done by calling EntitySpaces esPlugIn methods IsObjectType and IsArrayType

  foreach(IColumn col in cols)
  {
    if(!esPlugIn.IsArrayType(col) && !esPlugIn.IsObjectType(col))
    {//exclude fields like TimeStamps
         //put your code here
    }
  
  }

My notes about MyGeneration Templates

I’ve started to use MyGeneration  templates. They are very powerful and easy to customize. However I feel it is not always easy to find documentation.It is split between different sites and also not searchable by Google(see discussions here and here).So I decided to put  here the links that are useful for me .

The introductiontoMyGeneration can be found in articles on CodeProject and dotnet.sys-con.com.

MyGeneration allows to write scripts in VBScript,JScript, C# and VB.Net. In DotNetScript UI can be written using use the standard .Net windows forms and propriatory Zeus input form. I prefer to use C# DotNetScript with using WinForms -and the authors of EntitySpaces use the same in their ASP.NET templates. However many of the old templates in the Template Library are written using other languages, which makes it a little bit harder to copy and paste code snippets. 

There is set of articles in TemplateLibrary.
For me the most useful are Developing DotNetScript Templates – MyGeneration  and MyGeneration Project Files.
(don’t waste your time to open articles, authored by lmterra  – they currently refer to dead links).

In forums site there is Tips and Tricks forum with Include Files in MyGeneration, , Your First MyGeneration Plug-In and SubTemplate Execution  tips.

The procedure of debugging is described here and in the help  . However I found it is required some tricks to show source – see Debug in VS2005 thread.

To  create easier UI for templates see MyGeneration.zip in dOOdads ASP.NET Inline Grid archive and in particular comment at the end of the post from  my.generation :

I added the project that I used to create the UI to the archive. It’s called MyGeneration.zip. MyMeta wont run unless you call the application MyGeneration, thus the name. Anyway, notice the use of the variable “input” which is a hash table, when I copy this code in the UI I only copy the code from MyForm_Load() on down. It makes for an extremely fast way to write/debug full winform UI’s. Just change the connection string in the Main() function where it creates and initializes a MyMeta object.

See also discussion Creating the GUI part of the template in Visual Studio

Alternative approach to creating UI in searate DLL shown in archive:Embedding Windows Forms in the Template UI .
Not sure, does Syntax-colouring plug-in for MyGeneration UI add any value,or current implementation sufficient.

Environment variables for template from Zeus API Reference Zeus.ZeusInput . The current template script metadata are accessible through  IZeusTemplateStub class.The sample to get them (e.g. Template Title) is shown here

To output ASP.NET dynamic tags <% and %> from templates see post .

I’ve posted template: Ajax Auto Complete WebServices using EntitySpaces

Links for Code Generator/ and O/R mappers for ASP.NET application

I had a requirement to find Code Generator that will help to port existing quite big Access application to ASP.NET and support multiple databases.

 

The codegeneration.net site provides quite a big list of applications that claims to do this.

 

I also was pointed by Paul Wilson’s  posts: (How do you decide what features to add or cut?, Debate: O/R Mapping or Code Generation  and others) that Dynamic SQLs in O/R mappers allow to avoid hundreds of CRUD stored procedures and DAL classes.
Unfortunately, most of O/R Mapper tool have nothing with web site generation. And most of ASP.Net generators do not use dynamic SQL, but generate stored procedures.
Only two products seem to do both: TierDeveloper–Alachisoft and EntitySpaces.
After downloading TierDeveloper I understood that they generate static parameterized SQL, not using O/R
engine generates queries at runtime. Also tehASP.NET pages they generated are quite messy.

The demo version of EntitySpaces Template Suite for ASP.NET looks very good, and they also have DNN templates, which is important for my development.

 

So it seems that EntitySpaces is the best choice for my project. (Touch the wood, 2 years ago I choose VBExpress generator and I am not much happy with that my choise).

 

UPDATE 29/12/2007: At the moment I am using EntitySpaces and quite happy with them.
I am going to try LINQ to SQL : Related links:
Linq to Sql: The Good, The Bad & The Bottom Line

ScottGu’s tutorials parts 1-9: LINQ to SQL  

See also Linq to Entities

Pro LINQ Object Relational Mapping with C# 2008 Book Review   

 

Below are differnet links that I’ve used for this research.

 

 

1         Overviews

  http://c2.com/cgi/wiki?ObjectRelationalToolComparisonDotNet

 

http://www.codeproject.com/dotnet/CodeGenResource.asp

 

The Code Project Survey: Which .NET data-tier generator do you use?

http://www.codegeneration.net/generators-by-platform.php?target=12&lang=20

http://www.123aspx.com/Directory.aspx?dir=303&ob=ratings&obd=desc&pNo=2

 

“How-To-Select an Object-Relational Mapping Tool for .NET” guide

 

1         Web Site ORM and Generators

 

1.1       EntitySpaces

 

http://www.entityspaces.net/

a free 45 day Trial Version

EntitySpaces Template Suite for ASP.NET

How to purchase

 

1.2       TierDeveloper–Alachisoft

TierDeveloper–Alachisoft

http://www.alachisoft.com/tdev/index.html

an object-to-relational mapping and code generation tool.

Enterprise $1495

Negative comment ,Negative comment

Dynamic SQL –actually generated in Data.Persistence.Factory.

Templates ASPX, not asmx

 

2         Web Site Generators

 

Overviews: http://sharptoolbox.com/categories/code-generators

 

2.1     CodeCharge

 

http://www.yessoftware.com/products/product_detail.php?product_id=1

 

Cost CodeCharge Studio  3.1  $499

Downloaded.

Tried to run against the database.. It stops for each table without primary key and asks to uncheck the table. It was too annoying to continue.

           

2.2       ASP.NET Maker 

 

http://www.hkvstore.com/aspnetmaker/demo.asp%20USD59.95   

Start from US$99.95

Fully working version for 30 days Downloaded

 

)

 

2.3       . Codejay

http://www.codejay.com/products.asp?p=database%20tool

 

 

 

2.4       GenWise Studio

Template-based code generator / IDE for ASP.NET with NHibernate support.

For use with o.a. SQL Server, Oracle, Sybase and MySql.

 

2.5       Iron Speed Designer

http://www.ironspeed.com/products/

an application generator that builds database-driven Web applications for .NET

$595

 

2.6      Web Application Code Generator by Gigaframe

http://www.codegenerator.ca/

No templates, no trial download $129

2.7       IronWorks

 

http://www.esolutionspr.com/IronWorks/

Use templates, Code Generator

2.8       CodeSmith -netTiers Application Framework

http://www.nettiers.com/

 

 

3          O/R mappers

 

See Paul Wilson’s .NET Blog:  The Best O/R Mappers: NHibernate, LLBLGen Pro, and EntityBroker

Also see http://www.mcse.ms/message1405638.html

Blog overview “looking for a good ORM” http://www.bzdz.com/topic/view/14/

Discussions here http://www.theserverside.net/news/thread.tss?thread_id=29914

Overviews: http://www.answers.com/topic/object-relational-mapping , http://www.theserverside.net/news/thread.tss?thread_id=40204#207699

http://madgeek.com/Articles/ORMapping/EN/mapping.htm

 

 

3.1       LLBLGen

http://www.llblgen.com/

Price per license EUR 229.00

Good Comments

Bad comment

3.2       Wilson WebPortal ORMapper

http://www.wilsonwebportal.com/

ORMapper

 

3.3       NHibernate

 

Lesser GPL Licence –is it acceptable?

http://nhibernate.sourceforge.net/

See NHibernate Quick Start Guide.

Support for ASP.NET -No, objects do not have a temporal primary key, they only get a primary key when saved so it is hard (impossible?) to reference them from controls like the Web DataGrid?, you have to add manually support for temporal primary key… or save to the database on each request/response cycle.

Manual creation of Business Objects.

3.4       EntityBroker

 

EntityBroker: Yes objects do have a temporal primary key, they get it when they are created in memory so it is easy to reference them from controls like the Web DataGrid?, and save only when the business transaction is ready.

3.5       TechTalk’s Genome

http://www.genom-e.com/

Support for Microsoft SQL, Oracle and IBM DB2
can switch to LINQ

€ 1800

Eval Downloaded

 

3.6       Frameworks included in the Object Relational Tool Comparison

 

From Object Relational Tool Comparison Dot Net

39. Support for ASP.NET (It means it plays well with the request/response cycle, allows saving objects in the session, unsaved objects have temporary in memory primary keys that allow transactions spanning multiple requests/responses without writing the transaction into the database, etc)(Visually?, Out of the box).

    • AtomsFramework: Unknown
    • GentleNet: Yes, although objects are uniquely identified by the primary key fields, which can be initialized from code or on insert. However, there is special support for caching and uniqing to ensure safe operation in ASP.NET environments.
    • NeoFramework: Unknown
    • OJB.NET: Unknown
    • LLBLGen Pro: Yes, fully supports ASP.NET 2.0 with own datasource control and 2-way databinding. Also fully support for ASP.NET 1.x and object serialization in viewstate/session.
    • NHibernateLibrary: No, objects do not have a temporal primary key, they only get a primary key when saved so it is hard (impossible?) to reference them from controls like the Web DataGrid?, you have to add manually support for temporal primary key… or save to the database on each request/response cycle.
    • Vanatec OpenAccess: Yes

 

 

3.7       EasyObjects.NET

http://www.easyobjects.net/
An Object/Relational Mapper (ORM) library written entirely in C# and built on top of Microsoft’s Enterprise Library and and MyGeneration’s dOOdads,
BL and Database only.

 

3.8       DataObjects.NET

http://www.x-tensive.com/Products/DataObjects.NET/

development of data and business tiers of the database application

 

  3.9      Castle ActiveRecord

http://www.castleproject.org/activerecord/index.html

Castle ActiveRecord is built on top of NHibernate, but its attribute-based mapping free the developer of writing XML for database-to-object mapping, which is needed when using NHibernate directly


Code Generator for ASP.NET application

I had a requirement to find Code Generator that will help to port existing quite big fat client application to ASP.NET and to support multiple databases.


 


The codegeneration.net site provides quite a big list of applications that claims to do this.


 


I also was pointed by Paul Wilson’s  posts (How do you decide what features to add or cut?, Debate: O/R Mapping or Code Generation  and others) that Dynamic SQLs in O/R mappers allow to avoid hundreds of CRUD stored procedures and DAL classes.
Unfortunately, most of O/R Mapper tool have nothing with web site generation. And most of ASP.Net generators do not use dynamic SQL, but generate stored procedures.
Only two products seem to do both: TierDeveloper–Alachisoft and EntitySpaces.
After downloading TierDeveloper I understood that they generate static parameterized SQL, not using O/R
engine generates queries at runtime. Also tehASP.NET pages they generated are quite messy.


The demo version of EntitySpaces Template Suite for ASP.NET looks very good, and they also have DNN templates, which is important for my development.


 


So it seems that EntitySpaces is the best choice for my project. (Touch the wood, 2 years ago I choose VBExpress generator and I am not much happy with that my choise).


You can see my draft research document with links and notes that I’ve used for this research.