Quantcast
Channel: EntityFramework Reverse POCO Code First Generator
Viewing all articles
Browse latest Browse all 1642

New Post: Custom Data Annotations

$
0
0
I need to serialize my entities with the JsonSerializer from Newtonsoft
but this serialize all properties including the Reverse Navigation and Foreign Keys.

The simplest way to exclude them is to use the data annotation "[JsonIgnore]"
so I modified the code to include 2 string[] with all the Data Annotations we want to write.

In EF.Reverse.POCO.Core.ttinclude
string[] AdditionalReverseNavigationsDataAnnotations = null;
string[] AdditionalForeignKeysDataAnnotations = null;
In Database.tt
AdditionalReverseNavigationsDataAnnotations = new string[] { "JsonIgnore" };  // To include extra Data Annotations for ReverseNavigationProperty, include them here. i.e. "JsonIgnore"
AdditionalForeignKeysDataAnnotations = new string[] {  };  // To include extra Data Annotations for ForeignKeys, include them here. i.e. "JsonIgnore"
And in EF.Reverse.POCO.ttinclude
<#
foreach(string s in tbl.ReverseNavigationProperty.OrderBy(x => x))
{
#>
    <#foreach (var rnpda in AdditionalReverseNavigationsDataAnnotations) {#>
    [<#=rnpda #>]
    <# } #>
    <#=s #>
<# } } #>

<#
foreach(var entityFk in tbl.Columns.SelectMany(x => x.EntityFk).OrderBy(o => o))
{
#>
    <#foreach (var fkda in AdditionalForeignKeysDataAnnotations) {#>
    [<#=fkda #>]
    <# } #>
    <#=entityFk #>
<# } } #>

Viewing all articles
Browse latest Browse all 1642

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>