2017-10-09 64 views
1

我正在使用ASP.Net Core 1.1。我的模型就像是这个 -ASP.NetCore - RuntimeBinderException:以下方法或属性之间的调用不明确

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之后,就像是这个 -

enter image description here

,我在控权

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) 

任何人都可以请帮助我,我做错了什么?

在此先感谢您的帮助。

+0

看看这个类似的问题:https://github.com/aspnet/EntityFrameworkCore/issues/8259。似乎这是EF核心库问题。 –

+0

在这种情况下,我该怎么办? @TetsuyaYamamoto –

回答

0

原因是因为Unsigned Int 64不是目前在实体框架中支持(如v6)。使用映射到SQL bigintLong而不是UInt64

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       | 
+--------------------+----------------------------+-------------------------------------+ 
+0

我已经尝试过'udouble',它也不起作用。然后,我尝试了'双',它的工作。 –

+0

非常感谢您帮助格式化表格 –

相关问题