似乎EF将零填充到我要保存的值,然后引发异常。这是我的代码:为什么总时数字段的值10.17超出十进制(6,5)值类型的范围,为什么将这个值填充为零?直接使用SQL Server Management Studio保存此值似乎不是问题,因此似乎更像是EF的问题。
这是来自数据库的第一个.edmx文件。我试过将比例和精度设置为无。都没用
var rVal = new Data.FactPayrollHour()
{
BereavementHours = 0.0M,
CostCenter = "MyCostCenter",
Department = "MyDepartment",
EmergencyHours = 0.0M,
HomeGroupCode = "MyHomeGroup",
PayrollEmployeeId = employees.FirstOrDefault().Id,
PayType = "MyPayType",
PunchDateKey = dateDims.FirstOrDefault().ID,
Schedule = "",
ServiceHours = 0.0M,
Shift = "",
ShortTermHours = 0.0M,
TimePolicy = "",
TotalHours = 10.17M,
UnpaidHours = 0.0M,
VacationHours = 0.0M
};
db.FactPayrollHours.Add(rVal);
db.SaveChanges();
异常消息为:Parameter value '10.17000' is out of range.
堆栈跟踪:
at System.Data.SqlClient.TdsParser.TdsExecuteRPC(SqlCommand cmd, _SqlRPC[] rpcArray, Int32 timeout, Boolean inSchema, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj, Boolean isCommandProc, Boolean sync, TaskCompletionSource`1 completion, Int32 startRpc, Int32 startParam)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<Reader>b__c(DbCommand t, DbCommandInterceptionContext`1 c)
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
at System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.Execute(Dictionary`2 identifierValues, List`1 generatedValues)
at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
答案 0 :(得分:1)
如果数据类型为decimal(6,5)
,则最多可以使用6个十进制数字进行存储,其中5个将在小数点后保留(这就是为什么在数字后加0的原因小数点)。
这使您在小数点前(左侧)留下1位数字。您正在使用2。 这就是为什么您有错误。