【问题标题】:ASP.NetCore - RuntimeBinderException: The call is ambiguous between the following methods or propertiesASP.Net Core - RuntimeBinderException:以下方法或属性之间的调用不明确
【发布时间】:2017-10-09 12:42:10
【问题描述】:

我正在使用ASP.Net Core 1.1。我的模型是这样的-

public class JobCircular
{
    [Key]
    public UInt64 Id { get; set; }

    public string Name { get; set; }
    public string Detail { get; set; }
    [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd HH:mm:ss.S}", ApplyFormatInEditMode = true)]
    [DataType(DataType.Date)]
    public DateTime StartDate { get; set; }
    [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd HH:mm:ss.S}", ApplyFormatInEditMode = true)]
    [DataType(DataType.Date)]
    public DateTime EndDate { get; set; }

    [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd HH:mm:ss.S}", ApplyFormatInEditMode = true)]
    [DataType(DataType.Date)]
    public DateTime AddedDate { get; set; }

    [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd HH:mm:ss.S}", ApplyFormatInEditMode = true)]
    [DataType(DataType.Date)]
    public DateTime LastModifiedDate { get; set; }

    public DbSet<Teacher> Teachers { get; set; }

    public JobCircular()
    {
        AddedDate = DateTime.UtcNow;
        LastModifiedDate = DateTime.UtcNow;
    }
}

我的 DBModel 数据库是这样的-

我正在控制器中执行此操作-

using (var context = new ApplicationDbContext())
{
    Random rnd = new Random();
    UInt16 year = (UInt16)rnd.Next(1999, 2017);

    var jobCircular1 = context.JobCirculars;

    JobCircular jobCircular = context.JobCirculars
                                .SingleOrDefault(j => j.Id == 1);

    ...........................
    ...........................
}

我得到了这个错误-

An unhandled exception occurred while processing the request.

RuntimeBinderException: The call is ambiguous between the following methods or properties: 'Microsoft.EntityFrameworkCore.Storage.RelationalSqlGenerationHelper.GenerateLiteralValue(float)' and 'Microsoft.EntityFrameworkCore.Storage.RelationalSqlGenerationHelper.GenerateLiteralValue(decimal)'
CallSite.Target(Closure , CallSite , RelationalSqlGenerationHelper , object )

谁能帮我解决我做错了什么?

提前感谢您的帮助。

【问题讨论】:

标签: c# asp.net asp.net-mvc asp.net-core asp.net-core-mvc


【解决方案1】:

原因是因为Unsigned Int 64当前在实体框架中得到支持(在 v6 中)。使用 Long 而不是映射到 SQL bigintUInt64

Conversion Table

+--------------------+----------------------------+-------------------------------------+
| C# DataType        | Related DB Column DataType | PK Column DataType & Length         |
+--------------------+----------------------------+-------------------------------------+ 
| int                | int                        | int, Identity column increment by 1 |
| string             | nvarchar(Max)              | nvarchar(128)                       |
| decimal            | decimal(18,2)              | decimal(18,2)                       |
| float              | real                       | real                                |
| byte[]             | varbinary(Max)             | varbinary(128)                      |
| datetime           | datetime                   | datetime                            |
| bool               | bit                        | bit                                 |
| byte               | tinyint                    | tinyint                             |
| short              | smallint                   | smallint                            |
| long               | bigint                     | bigint                              |
| double             | float                      | float                               |
| char               | No mapping                 | No mapping                          |
| sbyte              | No mapping                 |                                     |
| (throws exception) | No mapping                 |                                     |
| object             | No mapping                 | No mapping                          |
+--------------------+----------------------------+-------------------------------------+

【讨论】:

  • 我已经尝试过udouble,但它也不起作用。然后我尝试了double,它成功了。
猜你喜欢
  • 2021-06-07
  • 2012-02-09
  • 2020-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多