How to Upgrade to DBContext from ObjectContext and what to do with default constructors. RRS feed

  • Question

  • For our newer projects we are using DBContext in Model First but we are currently upgrading some of our older Model First projects to DBContext T4 Genderation from ObjectContext Default/Legacy Generation.

    The area that is stumping me is that we have some Partial Classes that extend the generated classes. This is done mostly for adding validation attributes but also we have few classes that define a default constructor for the class to populate default values for properties.

        public partial class Case     {
            public Case()
                DateEntered = DateTime.Now;
        public class Case_Validation
            [Display(Name = "Case Id", Order = 1)]
            public int Id { get; set; }
            public int PersonId { get; set; }
    The problem is that the T4 Template also generates a default constructor.  So I need some guidance in this upgrade scenario. How do you set the default values with DBContext so that when the object gets newed up it will by default have those property values assigned?


    Friday, April 11, 2014 4:46 PM