Solved

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

Posted on 2011-09-17
1
375 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now