Do viewmodels need keys?

前端 未结 2 1816
孤城傲影
孤城傲影 2021-02-10 12:29

I have my view model :

namespace projInterview.Models
{
    public class QuestionViewModel
    {
        public piQuestion Question { get; set; }
        public          


        
2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-10 13:21

    For the sake of completion: when selecting a model in the View scaffolder, a domain model is expected, so it also pre-populates the Data context class and as such it expects a key. When selecting a viewmodel, simply delete the pre-filled DAL class and leave the DAL field blank.

    View Scaffolder

    If you actually define a key for a viewmodel, as I wrongly did, the scaffolder adds a definition of the viewmodel to the context class. To remedy the mess I had made, I deleted the viewmodel definitions from my context class and removed the keys from my viewmodels.

    I finally got the idea from this answer.

提交回复
热议问题