?
Solved

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

Posted on 2011-09-17
1
Medium Priority
?
383 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 3

Accepted Solution

by:
ExpertLogin_890 earned 2000 total points
ID: 36559233
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

752 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