Using the description property of SQL Server fields as the friendly name

SQL Server allows each field in the database to have a description, so this description seems like the most useful place to put friendly names for fields that will appear on a netTiers generated admin page. When netTiers first runs, a config file is generated as specified in 01 MappingFile This XML file lists all of the tables and for each table it lists all of the fields e.g. <Column Id="title" CSType="System.String" PropertyName="Title" FieldName="_title" FriendlyName="Title" IncludeInOutput="true" /> netTiers will automatically convert the database field name of “title” to a FriendlyName of “Title” It’s quite clever too and will convert a field name of "title_or_salutation" to a FriendlyName of "Title Or Salutation" ...

March 17, 2011 · 2 min

Using stored procedures in entity data sources

The normal <asp:SqlDataSource/> can use stored procedures as the select method and even for insert/update/delete commands. netTiers will create a strongly typed data source for each table. The inserts, updates and deletes are handled automatically but there are options for which records to select. Get_Paged is the default but you can also get by any foreign key. Sometimes this isn’t enough and you want a custom filter for your entities. To do this, write a stored procedure that returns all of the columns in the base table and no other columns. The SP can have joins to other tables, so you can use those for filtering. The SP can have whatever parameters you like. Because the SP returns all of the columns of the base table, netTiers recognises that it can be used to get a list of entities and so allows it as a SelectMethod e.g. ...

February 18, 2011 · 2 min

transactions and creating related records on insert

After creating a record, you might want to automatically create a related child record, which uses the ID of the record you have just created. In your datasource <data:XyzDataSource> you can put in OnInserted="Xyz_Inserted": <data:XyzDataSource ID="XyzDataSource" runat="server" SelectMethod="GetById" OnInserted="Xyz_Inserted"> protected void Xyz\_Inserted(Object sender, ObjectDataSourceStatusEventArgs e) { if (e.Exception == null) { if (FormView1.CurrentMode == FormViewMode.Insert) { Xyz myXyz = (Xyz)e.ReturnValue; int ID = myXyz .Id; // now create the child entity, set the parent id and insert it } } } The problem with this is that netTiers by default uses transactions and Xyz_Inserted is called in the middle of the transaction. So, whilst an ID has been returned for the new record, it hasn’t been committed to the database, so you can’t create the child record yet. The way around this is for the datasource to not use transactions. ...

February 9, 2011 · 1 min

Database connections timing out in IIS 7.5 – caused by EntityTransactionModule

Problem: After using a netTiers powered website for a while, the database connections would start to time out and you’d get a Stack Trace like: at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error) Solution: NetTiers was using an EntityTransactionModule which was incorrectly configured. It was opening database connections and not closing them (I think) and so SQL Server eventually stops allowing connections. IIS 7.5 needs the following code in the web.config to correctly configure the module. ...

February 8, 2011 · 1 min

NetTiers EntityGridView Deepload display readonly lookup

If you need your netTiers gridview (EntityGridView) to have a column that just displays a read only value from a lookup table then the data source will need to deepload but <asp:BoundField> won’t be able to access the lookup value. NetTiers’ own controls are only dropdowns, hyperlinks and radiobuttons, so to display the lookup value (rather than the ID), you need to add a template field <asp:TemplateField> <ItemTemplate> <%# Eval("ApplicIdSource.Applic")%> </ItemTemplate> </asp:TemplateField> as described here: ...

February 8, 2011 · 1 min

ID fields

Don’t name a field ID, id or Id If you ask NetTiers to generate an admin website, then it will show warnings when compiled but these will result in errors when you try to run the site. Even if you don’t want an admin website to start with, you may want one later, so just don’t name any fields ID

November 25, 2010 · 1 min

IF statements in custom stored procedures

You may want your custom stored procedures to contain conditional statements such as IF. These can cause problems when NetTiers inspects the procedure to determine its outputs – it may normally return a table but an IF statement traps for an exception and conditionally returns before the select statement. You can force NetTiers to follow one route through the code e.g. the statement below will never return for NetTiers IF user_name() <> 'NetTiersUserAccount' AND ThingToTest = ValueThatMakesItReturn RETURN Just make sure that the user account in the connection string used by NetTiers is not used by anything other than NetTiers i.e. not in you web.config

August 25, 2010 · 1 min

System.Reflection.AmbiguousMatchException: Ambiguous match found.

If you get this error with NetTiers, it’s probably because you have a field named with a reserved word such as: Tag ID SortOrder Rename the field

October 20, 2009 · 1 min

completely close and re-open NetTiers after database changes

If you have NetTiers open and have generated code, then make changes to the database, you need to completely close and re-open CodeSmith / NetTiers for it to fully recognise the changes. Something or other gets cached and NetTiers doesn’t spot the database changes – this was a pain to track down.

September 24, 2009 · 1 min

SortOrder

Don’t call a field in the database “SortOrder” It breaks nettiers in subtle ways that are hard to spot

September 23, 2009 · 1 min