我得到這個錯誤:得到錯誤:在「匹配」的「ID」屬性不能被設置爲「System.Int32」值
上「匹配」不能在「ID」屬性設置爲'System.Int32' 值。您必須將此屬性設置爲 'System.Int64'類型的非空值。 「
一個代碼片斷,如:
Match _match =_entities.Match.SingleOrDefualt(match => match.Id == MatchId);
它發生有時並不是所有的時間和我檢查我的數據庫POCO類的類型,它是正確的 我使用EF 6.1.3
代碼首先我! !很困惑
我的實體類是:
[Table("Match")]
public class Match
{
public Match()
{
Hands = new HashSet<Hand>();
Rounds = new HashSet<Round>();
}
public long Id { get; set; }
public DateTime CreationDate { get; set; }
public long FirstPlayerId { get; set; }
public byte FirstPlayerRedrawHandCount { get; set; }
public long? SecondPlayerId { get; set; }
public byte SecondPlayerRedrawHandCount { get; set; }
public byte SpeedType { get; set; }
public MatchType MatchType { get; set; }
public byte FirstPlayerScore { get; set; }
public byte SecondPlayerScore { get; set; }
public MatchStatus Status { get; set; }
public long? DCUser { get; set; }
public DateTime? RetryTime { get; set; }
[Timestamp]
public byte[] RowVersion { get; set; }
public RegisterState RegisterState { get; set; }
[ForeignKey("FirstPlayerId")]
public virtual User User { get; set; }
[ForeignKey("SecondPlayerId")]
public virtual User User1 { get; set; }
public virtual ICollection<Hand> Hands { get; set; }
public virtual ICollection<Round> Rounds { get; set; }
}
什麼是'MatchId'在'比賽_match = _entities.Match。 SingleOrDefualt(match => match.Id == MatchId);'?這是從哪裏來的?顯示更多的代碼。 –
也許'match.Id == Convert.ToInt64(MatchId)' –
@NikhilAgrawal,這不是問題。錯誤消息是關於分配,而不是比較。問題必須是實體在Match實例中試圖將數據放在表上時。 – Jauch