我也覺得有一些不匹配與.NET版本和EF6,這使得程序從一個錯誤的組裝取[NotMapped]註釋。
特別地,該問題是在使用這兩個參考文獻的:System.ComponentModel.DataAnnotations; System.ComponentModel.DataAnnotations.Schema。
我注意的是,在這種情況下,我們不能用在同一個類文件中同時引用,因爲NotMapped屬性將被分配到不同的DLL預期的。即使您在代碼中指定了此引用中的一個,但未將指令使用(例如在屬性聲明中放置完整引用),該程序仍然會存在此錯誤。
要解決此問題,我從類中刪除了引用System.ComponentModel.DataAnnotations,只留下System.ComponentModel.DataAnnotations.Schema引用以使用NotMapped屬性。爲了提供第一個引用(表單驗證操作)的遺漏,我在客戶端實現了驗證(使用jquery + javascript)。
using System;
using System.Collections.Generic;
//using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
public partial class Account
{
//[System.ComponentModel.DataAnnotations.Required(ErrorMessage = "O campo nome é obrigatório!")]
//[System.ComponentModel.DataAnnotations.StringLength(50, ErrorMessage = "O campo nome deve possuir no máximo 50 caracteres!")]
//[System.ComponentModel.DataAnnotations.Display(Name = "Nome")]
public string Name { get; set; }
//[System.ComponentModel.DataAnnotations.Required(ErrorMessage = "O campo nome é obrigatório!")]
//[System.ComponentModel.DataAnnotations.StringLength(100, ErrorMessage = "O campo email deve possuir no máximo 100 caracteres!")]
//[System.ComponentModel.DataAnnotations.Display(Name = "Email")]
public string Email { get; set; }
//[System.ComponentModel.DataAnnotations.Required(ErrorMessage = "O campo senha é obrigatório!")]
//[System.ComponentModel.DataAnnotations.Display(Name = "Senha")]
//[System.ComponentModel.DataAnnotations.DataType(System.ComponentModel.DataAnnotations.DataType.Password)]
[NotMapped]
public string Password { get; set; }
//[System.ComponentModel.DataAnnotations.Required(ErrorMessage = "O campo confirmação de senha é obrigatório!")]
//[System.ComponentModel.DataAnnotations.Display(Name = "Confirmação da senha")]
//[System.ComponentModel.DataAnnotations.DataType(System.ComponentModel.DataAnnotations.DataType.Password)]
//[System.ComponentModel.DataAnnotations.Compare("Password", ErrorMessage = "A confirmação da senha está diferente da senha informada.")]
[NotMapped]
public string ConfirmPassword { get; set; }
是否有一些代碼在你遇到異常的地方? – 2014-09-03 14:20:53
無處不在我得到,更新或放到數據庫和我包括的[NotMapped]屬性我得到錯誤:無效的列名稱'Authenticated'。 (或者不管列/屬性被調用)。在這種情況下使用用戶對象的碼是一個簡單的存儲庫調用:公共實際的t FirstOrDefault(表達式>其中) { 返回_objectSet.FirstOrDefault(其中); } –
Gruffalon
2014-09-04 06:09:05