Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to convert a C# string to a SqlChars?

I'm creating some unit tests for a piece of code that returns a SqlGeography type. To mock up the SqlGeography column I'd like to use SqlGeography.STLineFromText to create a line string. Problem is STLineFromText takes SqlChars as a parameter. Does anyone know how to convert a C# string to SqlChars?

like image 743
NullReference Avatar asked Jun 04 '12 21:06

NullReference


3 Answers

new SqlChars(new SqlString(text));
like image 85
SLaks Avatar answered Oct 16 '22 18:10

SLaks


Use this:

new SqlChars(text.ToCharArray());
like image 28
Nikola Bogdanović Avatar answered Oct 16 '22 19:10

Nikola Bogdanović


You should be able to use the SqlChars constructor:

SqlChars c = new SqlChars("test".ToArray());
like image 2
Abe Miessler Avatar answered Oct 16 '22 19:10

Abe Miessler