1層(MVC)のみのMVC3を使用して簡単な調査ツールを作成しました。私は今これを後悔しています。私のすべてのデータベースアクセスとマッピングは、コントローラーと他のいくつかのマッピングクラスで処理されます。
3つのレイヤーの使用に切り替えたいと思います。
プレゼンテーション(MVC)
ビジネスロジック
データ/永続性(EF)
私はEntityFrameworkを使用して、データベースですべてを処理しています。エンティティフレームワークは、独自のドメインクラスを作成します。MVCが使用するモデルとEFが作成するモデルの間のマッピングはどこに行くべきですか?
マッピングがビジネスレイヤーにある場合、MVCプロジェクトにModelsフォルダーが必要ですか?
調査質問は、質問自体、行と列で構成されます。これらは私が使用するモデルです:
public class Question {
        public int Question_ID { get; set; }
        public Boolean Condition_Fullfilled;
        [Required(ErrorMessage = "Dette felt er påkrævet")]
        public String Question_Wording { get; set; }
        public String Question_Type { get; set; }
        [Required(ErrorMessage = "Dette felt er påkrævet")]
        public String Question_Order { get; set; }
        public String Left_scale { get; set; }
        public String Right_scale { get; set; }
        public int Scale_Length { get; set; }
        public String Left_Scale_HelpText { get; set; }
        public String Right_Scale_HelpText { get; set; }
        public Boolean Visible { get; set; }
        public Boolean IsAnswered { get; set; }
        public String Question_HelpText { get; set; }
        public int Category_ID { get; set; }
}
public class MatrixColumns
    {
        public int Column_ID { get; set; }
        public int Column_Number { get; set; }
        public String Column_Description { get; set; }
        public Boolean IsAnswer { get; set; }
        public int? Procent { get; set; }
        public bool Delete { get; set; }
        public bool Visible { get; set; }
        public int? Numbers { get; set; }
        public String Help_Text { get; set; }
    }
    public class MatrixRows
    {
        public bool Delete { get; set; }
        public bool Visible { get; set; }
        public int Row_Id { get; set; }
        public String Row_Number { get; set; }
        public String Row_Description { get; set; }
        public String Special_Row_CSS { get; set; }
        public String Help_Text { get; set; }
        // Dette er summen af procenterne af alle kolonner i rækken
        public int RowSum { get; set; }
    }
これらのモデルのすべてのデータは、QuestionIDに基づいてコントローラーで取得され、次のようなViewModelにマップされます。
 public class ShowMatrixQuestionViewModel : Question
    {
        public Dictionary<MatrixRows, List<MatrixColumns>> columnrow { get; set; }
        public List<MatrixColumns> columns { get; set; }
        public List<MatrixRows> rows { get; set; }
        public ShowMatrixQuestionViewModel()
        {
            columns = new List<MatrixColumns>();
            rows = new List<MatrixRows>();
            columnrow = new Dictionary<MatrixRows, List<MatrixColumns>>();
        }
    }
それでShowMatrixQuestionViewModel、コントローラーからビューにを送信したい場合、どのルートを取る必要がありますか?
これは私の提案です:
->コントローラーはビジネスレイヤーのメソッドを呼び出します
public ShowMatrixViewModel GetQuestion(int QuestionID) {}
-> GetQuestionは、データレイヤーで次のメソッドを呼び出します。
public Question GetQuestion(int QuestionId) {}
public MatrixRows GetRows(int QuestionId) {}
public MatrixColumns GetColumns(int id) {}
-> Entity Frameworkは、上記で投稿したオブジェクトにマップしたい「純粋な」オブジェクトを返します
-> GetQuestionは、EFモデルを自分のモデルにマップするメソッドを
呼び出します->最後のGetQuestionは、Questions、Rows、および列:
    ShowMatrixQuestionViewModel model = MapShowMatrixQuestionViewModel(Question, MatrixRows, MatrixColumns)
return model;
これは正しいです?
前もって感謝します