Skip to content

Frequently Asked Questions

Jereme Guenther edited this page Dec 22, 2018 · 5 revisions

General .netTiers

How to add generated classes to already existing project?

You'll need to install CodeSmith, and you can get a free eval copy from the CodeSmith website. Once you've done that go to the Getting Started section of this wiki for step by step instructions.

What about using .netTiers with VB.NET?

It can be done! .netTiers generates C#, but the assemblies are CLS-compliant. This means that you can build a system from any combination of .NET languages and things generally work the way you expect. There are some VB Gotchas though, so make sure you read up before you consider mixing VB.NET with .netTiers.

How fast is .netTiers compared with other code generators/Object-Relational Mappers?

One company was kind enough to compare multiple different data access layers. In all their tests, netTiers proved to be the fastest, in most cases by a reasonable margin. .netTiers achieves this speed through simplicity. While there is C# wrapped around the functions to give additional features, the actual data exchange with the database server is handled primarily through stored procedures with very simple queries. Complicated joins and where clauses often generated by other data access layers are not part of the core functionality of netTiers .

Who is .netTiers for?

.netTiers is a tool ideally suited for developers that have a good idea about database schema design and C# development patterns and practices. It also helps if the developer knows a bit about Code Smith since that is the tool used to generate the .NetTiers. Because .netTiers is not a commercial tool there are some rough edges, these are being worked on to constantly improve the development process as such, it would be helpful to have a strong senior architect \ developer on the team to keep the structure secure while working out any kinks.

Code Generation

How can I refresh my Database schema cache?

If CodeSmith isn't recognizing the changes in your database schema, try clicking the [...] button of the SourceTables or SourceDatabase properties from your property set. Alternatively, you can close and re-open CodeSmith. UPDATE: In CodeSmith 4.1+, there is a refresh schema button on the property grid toolbar.

Why is .netTiers not picking up column type changes in my views?

When a table changes in SQL Server specifically, it does not always update the meta data for the view. .netTiers uses the views meta data when generating the object representing the view. The fix is to open up the view, and re-execute it, then .netTiers should pick up correct information.

Entity Layer

How much deep-loading functionality does .netTier generate?

It is possible to deep load an object graph that represents a set of related tables. The API contains several deep-load options that offer control over recursion, parent/child inclusion, exactly which entity types (tables) should be included.

Deep-load works the best when loading related data that has a tree-like structure. Deep-load will attempt to handle recursive or circular relationships, but depending on the circumstances, these structures may limit the effectiveness of deep-load.

Data Layer

I set the NetTiersProvider.DefaultCommandTimeout property, so why does my (slow) Sproc time out using the SQL provider?

Contrary to what you might think, the family of Execute* functions in Data.Bases.NetTiersProvider.ProviderBase as implemented by SqlNetTiersProvider, does not honor/implement the DefaultCommandTimeout found in NetTiersProvider as the CommandTimeout value for command execution.

Barring a change to the templates, a possible workaround is the following code:

// adjust command timeout if the provider is a SQL database
Data.SqlClient.SqlNetTiersProvider p = DataRepository.Provider as Data.SqlClient.SqlNetTiersProvider;

if (null == p) {
    // provider is not a SQL provider, do something else appropriate
    DataRepository.Provider.ExecuteNonQuery("sp_MySlowSproc");
} else {
     // get the SqlDatabase   Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase db = new SqlDatabase(p.ConnectionString);
    // create a command for the slow sproc
    System.Data.Common.DbCommand cmd = db.GetStoredProcCommand("sp_MySlowSproc");
    // set the timeout as set on the provider (or as needed)
    cmd.CommandTimeout = DataRepository.Provider.DefaultCommandTimeout;
    // execute the command (any of the Execute* family)
    DataRepository.Provider.ExecuteNonQuery(cmd);
}

Another possibility would be to make use of the method:

Data.SqlClient.StoredProcedureProvider.GetCommandWrapper()

but it would only replace approximately 2 of the lines above, and considering the useStoredProcedure parameter it doesn't seem that appropriate.

How can I get a count of the Total Items in a table?

Issue: GetTotalItems() method on an EntityProvider object uses the same SQL as the Get() methods, which results in an entire record set being retrieved when all that is needed is to get a Count of the items in the database table.

Workaround: Call the GetPaged()method directly, but only specify a pageLength of 1. The out parameter of the method will contain the correct count. Example: (Using AdventureWorks DB)

int retVal;
TList<Product> prod = DataRepository.ProductProvider.GetPaged(0,1, out retVal);
return retVal;

This still returns a single entity item (if any exist), but this is at least more efficient than returning an entire table's data to simply get a count.

GetPaged doesn't return the correct page

Issue: start parameter indicates "Row number at which to start reading". In fact, the start parameter indicates what page to retrieve. Supplying a row number to this parameter will return an incorrect page.

Workaround: Before passing a value to this parameter, it is advisable to divide the desired row number by the desired page size. This will return the correct result set containing the value required.

Component Layer

How does the DomainModel component layer implementation work?

Answer

How does the ServiceModel component layer implementation work?

Answer

Why don't some data access methods (such as Find) show up when I attempt to bind a data source to a service object?

There is no meta data telling the framework to display the function.

Place the following code above the method declaration:

[DataObjectMethod(DataObjectMethodType.Select)]
public virtual TList<YourObject> Find(string whereClause)

Recompile and you should now see that method available.

Web Layer

What is the Web Library?

The NetTiers Web Library is a set of Controls and Objects that provide powerful tools to make your web development projects with NetTiers much easier and more efficient. The Web Library offers both Strongly Typed DataSource Controls as well as the more generic EntityDataSource. These are inherited from the ObjectDataSource, but have been improved to exploit the functionality of the NetTiers framework. You can find more info in the Web Layer section of this wiki.

WinForms Layer

What is the WinForms library?

The WinForms library is similar to the NetTiers Web Controls library, but is still in a developmental stage. It will be a suite of Controls and Objects that will make your WinForms development easier and more efficient.

Unit Tests Layer

If I want to use NUnit to test the data access and entity layer, how can I generated the tests?

Answer

Web Services Layer

What is the WebServiceClient Layer? Why not just call the WebService directly?

Answer

Clone this wiki locally