Why is my Entity Framework turning from "2.87" to "2" (decimal field)?

I confirmed that the correct value "2.87" is included in the service .. and corresponds to the EF diagram, the type for the "Score" field is "Decimal" ... But in the database it says only "2",

   [OperationContract]
        public void AddHighScore(string strName, decimal dScore, int iLevel)
        {
            using (SQL2008R2_789485_punkouterEntities1 dc = new SQL2008R2_789485_punkouterEntities1())
            {
                HighScore oHighScore = new HighScore();
                oHighScore.Level = iLevel;
                oHighScore.Name = strName;
                //oHighScore.Name = dScore.ToString();
                oHighScore.Score = dScore;
                dc.AddToHighScores(oHighScore);
                dc.SaveChanges();
            }
        }


-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'HighScores'
CREATE TABLE [dbo].[HighScores] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Score] decimal(18,0)  NOT NULL,
    [Level] int  NOT NULL
);
GO
+5
source share
3 answers

You need to set the scale in decimal field. Change the Grade field to decimal (18.2)

See the Decimal Help file on MSDN

You can set the scale in EF by first selecting a field, then in the properties window you will see the Scale property (see image)

enter image description here

+18
source

decimal(18,0) 18 0 .

2. decimal(18,2) , 18 , 2 .

+7

( ) edmx.

-1

All Articles