brotherbill999
asked on
Entity Framework 4.1 Need a field to be Decimal is SqlServer and String in Model
Consider a field such as HourlyWage decimal(10, 2) in Sql Server.
I wish to show the $ while the user is editing.
So the model has
public string HourlyWage { get; set; }
Thus an impedance mismatch.
The solution is on reading from the database, to convert the HourlyWage from decimal to string.
And then when writing to the database, to convert the HourlyWage from string, stripping off the leading $, then saving as decimal.
What magic do I need to tell Entity Framework, so that it will perform this two-way translation.
Ideally, I want the Model in C# to be a decimal, not a string.
In this ideal case, the model correctly has type decimal.
Sending the decimal to the UI works fine.
Saving the formatted HourlyWage '$12.34 to the model requires stripping out the leading $
How is this done?
Thank you!
I wish to show the $ while the user is editing.
So the model has
public string HourlyWage { get; set; }
Thus an impedance mismatch.
The solution is on reading from the database, to convert the HourlyWage from decimal to string.
And then when writing to the database, to convert the HourlyWage from string, stripping off the leading $, then saving as decimal.
What magic do I need to tell Entity Framework, so that it will perform this two-way translation.
Ideally, I want the Model in C# to be a decimal, not a string.
In this ideal case, the model correctly has type decimal.
Sending the decimal to the UI works fine.
Saving the formatted HourlyWage '$12.34 to the model requires stripping out the leading $
How is this done?
Thank you!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.