3

Possible Duplicate:
SELECT @@DBTS using Linq to SQL
Sql binary to c# - How to get SQL binary equivalent of binary in c#

I have one SQL table with one binary column. It has some data in binary format.

e.g. 0x9A8B9D9A002020202020202020202020

I am using LINQ context to fetch the data from this table. Can anyone help me in getting this. Here is a sample code I am using,

IEnumerable<byte[]> query = context
                .ExecuteQuery<byte[]>("select empPWD from Employee where employeeId = E32");

When I run this code it gives an error, like need to do mapping something alike.

The exact error message;

The type 'System.Byte[]' must declare a default (parameterless) constructor in order to be constructed during mapping.

Please help me if anyone knows this.

6
  • 2
    Post the exact error if you want help. Commented Jun 7, 2012 at 11:48
  • What is the column type? image? varbinary? Commented Jun 7, 2012 at 11:53
  • @Ramhound - Please see my edits for exact error message. The column type is binary(16). Commented Jun 7, 2012 at 11:59
  • Hmmm you need to look at this stackoverflow.com/questions/528486/… Commented Jun 7, 2012 at 12:00
  • @V4Vendetta - It returns an integer form. Can I fetch it as is in the form of string. Commented Jun 7, 2012 at 12:09

1 Answer 1

0

Could you refactor it to:

IEnumerable<System.Data.Linq.Binary> query = 
           context.Employees.Where(e => e.employeeId == "E32").Select(e => e.empPWD);

I think that should work (assuming your context contains an Employees table class). To access the byte[], use ToArray() on each instance of type System.Data.Linq.Binary.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.