[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 389
  • Last Modified:

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!
0
brotherbill999
Asked:
brotherbill999
1 Solution

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now