2017-10-09 59 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

非常感謝您幫助格式化表格 –

相關問題