How to make all entities access:internal instead of public in EDMX?

前端 未结 4 1326
一个人的身影
一个人的身影 2021-01-11 16:53

I\'d like my Entity Framework model to generate entities with internal access modifier, instead of public. I use

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-11 17:27

    I wanted my entity container as well as the generated complex classes to be internal. First I set the "Entity Container Access" to internal. Next I added a container variable to the top of the "Model.tt" file after the initialization of the itemCollection variable. I found the container variable code in the "Model.Context.tt" file.

        var itemCollection = new EdmMetadataLoader(textTransform.Host, textTransform.Errors).CreateEdmItemCollection(inputFile);
        var container = itemCollection.OfType().FirstOrDefault();
    

    Next I changed

        <#=Accessibility.ForType(complex)#> partial class <#=code.Escape(complex)#>
    

    to

        <#=Accessibility.ForType(container)#> partial class <#=code.Escape(complex)#>
    

    I chose to modify the code in this way so that I could keep my complex class container access modifiers in sync with the container access modifier.

    Thank you Gert Arnold for leading me in the right direction.

提交回复
热议问题