私はEntity Frameworkデータベースを最初に使用しています。私はUserクラスのプロパティを検証する必要があったため、すべての検証で部分クラスとメタデータクラスを作成しました。データベースの最初のテンプレートを使用してコントローラを作成できません
namespace OnlineTest
{
using System;
using System.Collections.Generic;
public partial class User
{
public User()
{
this.tbl_purchase = new HashSet<Purchase>();
}
public int UserId { get; set; }
public string username { get; set; }
public string password { get; set; }
public string email { get; set; }
public bool EmailVerified { get; set; }
public string PhoneNo { get; set; }
public bool PhoneVerified { get; set; }
public string positionInBank { get; set; }
public string bankState { get; set; }
public string bankCity { get; set; }
public string bankPin { get; set; }
public string bankAddress { get; set; }
public string userType { get; set; }
public bool isActive { get; set; }
public System.DateTime dateRegistered { get; set; }
public System.DateTime lastLogin { get; set; }
public virtual ICollection<Purchase> tbl_purchase { get; set; }
}
}
部分とメタデータのクラス
namespace OnlineTest.Models
{
[MetadataType(typeof(UserMetadata))]
public partial class User
{
[NotMappedAttribute]
[Compare("password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
}
public class UserMetadata
{
[Required(ErrorMessage = "Please type a username")]
[Display(Name = "UserName")]
public string username { get; set; }
[Required(ErrorMessage = "Please type a EmailId")]
[EmailAddress(ErrorMessage = "E-mail is not valid")]
[Display(Name = "Email address")]
public string email { get; set; }
[Required(ErrorMessage = "Please type a Phone number")]
[Display(Name = "Phone Number")]
public string PhoneNo { get; set; }
[Required(ErrorMessage = "Please provide your position in the bank")]
[Display(Name = "Position in bank")]
public string positionInBank { get; set; }
[Required(ErrorMessage = "Please provide your bank's address")]
[Display(Name = "Bank's Address")]
public string bankAddress { get; set; }
[Required(ErrorMessage = "Please provide state where bank is situated")]
[Display(Name = "State")]
public string bankState { get; set; }
[Required(ErrorMessage = "Please provide city where bank situated")]
[Display(Name = "City")]
public string bankCity { get; set; }
[Required(ErrorMessage = "Please provide pincode of your banks location")]
[Display(Name = "Pincode")]
public string bankPin { get; set; }
[Required(ErrorMessage = "Please type a password")]
[Display(Name = "Password")]
public string password { get; set; }
}
}
しかし、私は、コントローラを生成しようとしていたときに、それは以下のエラーを投げているEnitityフレームワークによって作成された
クラス。 OnlineTest.User
とOnlineTest.Models.User
:
すべてのヘルプはあなたの部分クラスの定義は、基本的に次の2つの別々のクラスを定義していることを意味する、二つの異なる名前空間にある
多くの可能性のある原因が考えられます。これらのいくつかをお試しください:http://stackoverflow.com/questions/19920837/there-was-an-error-running-the-selected-code-generator-in-vs-2013-scaffolding –
@SteveGreene私はないと思います私の問題はあなたが私に与えたリンクに似ています。答えにいくつかのメソッドを試しましたが、うまくいきません。 – Shahzad
@simba理想的には、Modelに同じEntityクラスを使用したくないのが理想的です。なぜDataAnnotationで新しいModelクラスを作成しないのですか? – Win