Targeting SQL server 2005 in .NET 1.1 - XML columns

Posts   
 
    
ibs
User
Posts: 14
Joined: 10-Aug-2005
# Posted on: 28-Nov-2006 23:41:55   

Hello,

I'm writing some unit tests in .NET 1.1 that target the AdventureWorks in SQL 2005. However, one of the columns (Person.Contact.AdditionalContactInfo) is of XML type in SQL server. The generated code in PersistanceInfoGenerator (I'm using adapter templates) is shown below. Problems is the the SqlDbType.Xml enum option was added in .NET 2.0, so my generated code doesn't compile under .NET 1.1.

Is there any easy way to force XML columns to be typed as strings for .NET 1.1? Converting to .NET 2.0 isn't an option at the moment. But, as these are just for unit tests, I'm going to use different tables to work around this for the moment.

Thanks in advance. Murray


        Private Sub InitContactEntityMappings()
            MyBase.AddElementMapping( "ContactEntity", "AdventureWorks", "Person", "Contact", 15 )
            MyBase.AddElementFieldMapping( "ContactEntity", "ContactId", "ContactID", False, CInt(SqlDbType.Int), 0, 0, 10, True, "SCOPE_IDENTITY()", Nothing, GetType(System.Int32), 0 )
            MyBase.AddElementFieldMapping( "ContactEntity", "NameStyle", "NameStyle", False, CInt(SqlDbType.Bit), 0, 0, 0, False, "", Nothing, GetType(System.Boolean), 1 )
            MyBase.AddElementFieldMapping( "ContactEntity", "Title", "Title", True, CInt(SqlDbType.NVarChar), 8, 0, 0, False, "", Nothing, GetType(System.String), 2 )
            MyBase.AddElementFieldMapping( "ContactEntity", "FirstName", "FirstName", False, CInt(SqlDbType.NVarChar), 50, 0, 0, False, "", Nothing, GetType(System.String), 3 )
            MyBase.AddElementFieldMapping( "ContactEntity", "MiddleName", "MiddleName", True, CInt(SqlDbType.NVarChar), 50, 0, 0, False, "", Nothing, GetType(System.String), 4 )
            MyBase.AddElementFieldMapping( "ContactEntity", "LastName", "LastName", False, CInt(SqlDbType.NVarChar), 50, 0, 0, False, "", Nothing, GetType(System.String), 5 )
            MyBase.AddElementFieldMapping( "ContactEntity", "Suffix", "Suffix", True, CInt(SqlDbType.NVarChar), 10, 0, 0, False, "", Nothing, GetType(System.String), 6 )
            MyBase.AddElementFieldMapping( "ContactEntity", "EmailAddress", "EmailAddress", True, CInt(SqlDbType.NVarChar), 50, 0, 0, False, "", Nothing, GetType(System.String), 7 )
            MyBase.AddElementFieldMapping( "ContactEntity", "EmailPromotion", "EmailPromotion", False, CInt(SqlDbType.Int), 0, 0, 10, False, "", Nothing, GetType(System.Int32), 8 )
            MyBase.AddElementFieldMapping( "ContactEntity", "Phone", "Phone", True, CInt(SqlDbType.NVarChar), 25, 0, 0, False, "", Nothing, GetType(System.String), 9 )
            MyBase.AddElementFieldMapping( "ContactEntity", "PasswordHash", "PasswordHash", False, CInt(SqlDbType.VarChar), 128, 0, 0, False, "", Nothing, GetType(System.String), 10 )
            MyBase.AddElementFieldMapping( "ContactEntity", "PasswordSalt", "PasswordSalt", False, CInt(SqlDbType.VarChar), 10, 0, 0, False, "", Nothing, GetType(System.String), 11 )
            MyBase.AddElementFieldMapping( "ContactEntity", "AdditionalContactInfo", "AdditionalContactInfo", True, CInt(SqlDbType.Xml), 2147483647, 0, 0, False, "", Nothing, GetType(System.String), 12 )
            MyBase.AddElementFieldMapping( "ContactEntity", "Rowguid", "rowguid", False, CInt(SqlDbType.UniqueIdentifier), 0, 0, 0, False, "", Nothing, GetType(System.Guid), 13 )
            MyBase.AddElementFieldMapping( "ContactEntity", "ModifiedDate", "ModifiedDate", False, CInt(SqlDbType.DateTime), 0, 0, 0, False, "", Nothing, GetType(System.DateTime), 14 )
        End Sub

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 29-Nov-2006 03:21:55   

One option would be to download the SDK and recompile the SqlServerDBDriver to use VarChar instead of SqlDataType.Xml. This is on line 129 of SqlServerDBDriver.cs. Change it to and you should be able to read and write the value.

base.DBTypesAsProviderType[(int)SqlDbTypes.Xml] = SqlDbType.VarChar.ToString();     // SqlServer 2005 specific.
ibs
User
Posts: 14
Joined: 10-Aug-2005
# Posted on: 29-Nov-2006 22:41:44   

Thanks bclubb. I was hoping for something more light weight (ie: a property to set somewhere), but this will be worth knowing if I have to target a real database rather than one for testing.

Thanks again.