Entity Framework Database First regeneration make me lose manual changes

后端 未结 2 1542
梦谈多话
梦谈多话 2021-02-11 01:28

I\'m making a website with MVC .NET.

Since I\'m an old school programmer who learn to design database first, I opted for the Database first approach. I\'m also using \"c

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-11 02:15

    Don't edit the generated files. Ever. Just. Don't. Do. It.

    Instead, make your edits in partial files in a different directory. To add attributes, declare a Metadata class at the top of your partial class definition.

    [MetadataType(typeof(BlogMetadata))]
    public partial class Blog
    {
        // it's possible to add logic and non-mapped properties here
    }
    

    Now in your Metadata class, you can define attributes or other logic:

    public class BlahMetadata
    {
        [AllowHtml] 
        public string Content{ get; set; } 
    }
    

提交回复
热议问题