Solved

Entity Framework 4.1 Need a field to be Decimal is SqlServer and String in Model

Posted on 2011-09-17
1
377 Views
Last Modified: 2012-06-22
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
Comment
Question by:brotherbill999
1 Comment
 
LVL 3

Accepted Solution

by:
ExpertLogin_890 earned 500 total points
ID: 36559233
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question