You can change the code generation mechanism (the .tt file in my case or the T4 file) and add the DataMember to the DataMember property. To add it to the automatically generated POCO class, find <#=codeStringGenerator.Property(edmProperty)#> and add [DataMember] directly above it:
var simpleProperties = typeMapper.GetSimpleProperties(entity); if (simpleProperties.Any()) { foreach (var edmProperty in simpleProperties) { #> [DataMember] <#=codeStringGenerator.Property(edmProperty)#> <# } }
Some of the code above should already be in the T4 file. you may need to find it and modify it by adding [DataMember] .
In addition, you can create your DTO file in any place with the desired attributes. For example, the code below creates an interface for all objects in a folder named Interface, and also names the interface as I {EntityName} Repository.cs. You can generate DTO in the same way.
foreach (var entity in typeMapper.GetItemsToGenerate<EntityType>(itemCollection)) { var host = this.Host.ResolvePath("App.config"); var savepath = host.Replace("App.config","")+"Interface\\" + "I"+entity.Name+"Repository" +".cs"; var readpath = host.Replace("App.config","") + "Templates\\"; if (!File.Exists(savepath)) { using (StreamReader sr = new StreamReader(readpath+"RepositoryInterfaceTemplate.txt")) { String line = sr.ReadToEnd(); line = line.Replace("{RepositoryInterface}","I"+entity.Name+"Repository"); line =line.Replace("{EntityName}",entity.Name); using (StreamWriter sw = File.CreateText(savepath)) { sw.WriteLine(@line); } } } }
source share