I answered a question on the newsgroups on how *exactly* inheritence works when you use it implement UDTs in SQL Server 2005. Also wanted to record the explanation here....
It doesn't work like you'd expect inheritence to when to use T-SQL, because SQL Server is blissfully unaware of the inheritence relationships (they're not recorded in the system views).
So if the class Tiger inherits from the class Cat. Passing an instance of Tiger to the T-SQL stored procedure FeedTheCat:create procedure FeedTheCat (@thecat Cat) .... -- T-SQL here -- wouldn't work.
-- (Msg 206: operand type clash dbo.Tiger is incompatible with dbo.Cat)declare @t tigerexecute feedthecat @t
-- or this (Msg 529: explicit conversion ... is not allowed)declare @c catset @c = cast(@t as cat)execute feedthecat @c
If the Cat class has a public instance method called FeedMe and a public field called pawcount (both are inherited by Tiger), this wouldn't work in T-SQL:
-- this wouldn't workdeclare @t Tigerprint @t.FeedMe()print @t.pawcount
-- this woulddeclare @c Catprint @c.FeedMe()print @c.pawcount
You could, however, access these fields/methods on Tiger from .NET code, As in:// works fineTiger t = new Tiger();int paws = t.pawcount;// so does thisSqlString s = t.FeedMe();
Calling it in .NET code *through SqlCommand.ExecuteReader* (CommandText = "select sometiger.pawcount from zootab") wouldn't work.
Theme design by Jelle Druyts
Pick a theme: BlogXP sqlx BlogXP sqlx
Powered by: newtelligence dasBlog 2.0.7226.0
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2008, Bob Beauchemin
E-mail