1 回答

TA貢獻(xiàn)1982條經(jīng)驗 獲得超2個贊
什么版本的EF?我無法使用簡單的基于 EF6 EDMX 的數(shù)據(jù)庫優(yōu)先模型來重現(xiàn)這一點。
添加了這個過程:
CREATE PROCEDURE [dbo].[Insert]
@Value[decimal](18, 6) NULL
AS
BEGIN
Select @Value -- this would give `33` when passed `0.0033M` From C#
END
添加了數(shù)據(jù)庫優(yōu)先模型,生成
public virtual ObjectResult<Nullable<decimal>> Insert(Nullable<decimal> value)
{
var valueParameter = value.HasValue ?
new ObjectParameter("Value", value) :
new ObjectParameter("Value", typeof(decimal));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<Nullable<decimal>>("Insert", valueParameter);
}
并跑:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp24
{
class Program
{
static void Main(string[] args)
{
using (var db = new aEntities())
{
var result = db.Insert(0.0033M);
Console.WriteLine(result.First().Value);
Console.ReadKey();
}
}
}
}
輸出是
0.003300
- 1 回答
- 0 關(guān)注
- 111 瀏覽
添加回答
舉報