SQL Timestamp vs WCF
In my previous post (LINQ to SQL in multi layered + service apps), I mentioned how LINQ to SQL can be used in WCF apps but how to you deal with concurrency checking? One way is to use a Timestamp column in your tables. This is a binary type so how will WCF deal with that?
LINQ to SQL maps the SQL Timestamp type to the System.Data.Linq.Binary type. If you add a DataMember attribute to a System.Data.Linq.Binary field, it will work. WCF will not choke on that. So what does the client sees? Something like this: Service1.Binary.
This whole thing may leads to a few problems:
- Binary stuff is not very interoperable
- Service1.Binary != System.Data.Linq.Binary
One solution is to convert the info from Binary to String. Andrew Siemer posted a couple of extension methods that allow you to do just that. Check it out:
http://geekswithblogs.net/AndrewSiemer/archive/2008/02/11/converting-a-system.data.linq.binary-or-timestamp-to-a-string-and-back.aspx
Simple and easy and you can convert the data right into your LINQ to SQL queries.