Reputation: 572
Since most of the projects I work on are exclusively SQL Server 2005/2008 database driver, I was wondering about the implications of using System.Data.SqlTypes classes as data types in my VB.Net Framework 4.0 code. For example currently I define integer variables as
Dim X as Integer
Using System.Data.SqlType classes I would define my intege variables as
Dim X as System.Data.SqlTypes.SqlInt32
Please comment on the implications for performance, serialization and databinding. One difference would be that all variables would default to Null.
Upvotes: 2
Views: 430
Reputation: 467
Its a bad idea because if someday you need to migrate from sql server to another database you will have to change all the vars in your code to the right type. (And all the castings, etc...)
Also, if you need null variables you can always use
Dim x As Nullable(Of Integer)
Also, for exaple integers are inmutable value types iso reference types like SqlInt32 and are much more optimized.
Value types vs reference:
http://msdn.microsoft.com/en-us/library/t63sy5hs%28v=vs.80%29.aspx
What is the difference between a reference type and value type in c#?
So probably SqlTypes will be slower and also will force you to stay forever on sqlserver.
Also consider that these types are not available for all the framework versions, and your code could be in some situations not very reusable, just for using these data types.
Upvotes: 1
Reputation: 13561
I don't think there's a lot of problems with the idea, serialization and databindinding should work, and I wouldn't worry about performance unitl it's an issue.
But while it would work, I don't think it's a good design. You will end up using sqltypes in areas that have nothing to do with sql. Other than as parameters to sql commands, sqltypes have no advantage over nullables, which are more generic.
Upvotes: 1