views:

1663

answers:

6

If you have a float in MSSQLServer, to what do you map this in .NET?

Can you convert it to Double or will you loose numbers?

thx, Lieven Cardoen

A: 

C# has a float type, but it will convert to double just fine as well.

Joel Coehoorn
A: 

From my recollection, most of the ORM tools will map it to a Decimal type, which will not lose precision like a double or float.

flatline
+14  A: 

SQLServer float and C#/VB double have the same representation. This is the correct mapping. What you don't want to do is map SQL Server float to C#/VB float as that may involve a loss of precision. SQL Server real maps onto C#/VB float.

T-SQL float and real type definitions can be found at MSDN. C# double definition can be found at MSDN as well, as can the float definition.

tvanfosson
A: 

It depends on the size of the SQL float. For plain "float" which is equivalent to float(53), you need to use a C# double. For float(24) or lower a C# float will be enough, or a double would work as well.

CodeMonkey1
A: 

The automatic code generated by Microsoft XSD convert SQL float (default float) to C# double.
So you can suggest that it isn't big mistake.
Until you working with float that have default size.

Avram
+2  A: 

Check out:

In your case SQL Server native type float maps to SQL Server CLR SqlDouble and then Double in .Net

kristof