0
votes

I use the instructions from Adding [DataMember] [DataContract] attributes in Entity Framework POCO Template

At first it worked, all of my complex types are generated with wcf attributed [DataContract] [DataMember]. And then when I regenerate, I don't know why all of my Complex Types have no [DataContract] [DataMember]. Only the entities have [DataContract][DataMember]

[DataContract]
<#=Accessibility.ForType(entity)#> <#=code.SpaceAfter(code.AbstractOption(entity))#>partial class <#=code.Escape(entity)#><#=code.StringBefore(" : ", code.Escape(entity.BaseType))#>
{
<#
    region.Begin("Primitive Properties");

    foreach (EdmProperty edmProperty in entity.Properties.Where(p => p.TypeUsage.EdmType is PrimitiveType && p.DeclaringType == entity))
    {
        bool isForeignKey = entity.NavigationProperties.Any(np=>np.GetDependentProperties().Contains(edmProperty));
        bool isDefaultValueDefinedInModel = (edmProperty.DefaultValue != null);
        bool generateAutomaticProperty = false;



#>

    [DataMember]
    <#=PropertyVirtualModifier(Accessibility.ForProperty(edmProperty))#> <#=code.Escape(edmProperty.TypeUsage)#> <#=code.Escape(edmProperty)#>
    {









//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated from a template.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Runtime.Serialization;
<#=String.Join(String.Empty, extraUsings.Select(u => "using " + u + ";" + Environment.NewLine).ToArray())#>
<#+
    fileManager.EndBlock();
}
1
Can you post your code, also is it possible for you to go back o the point at which it worked?Shiraz Bhaiji
i edited my question and posted my code. I tried to go back to which it worked, but I couldn't. I even tried to delete the t4 template and re-do it, but it did not work.qme
Please edit your question down to a reasonable length. Only post relevant code.Kirk Broadhurst

1 Answers

0
votes

Have you tried with the following extension?
It is for EF5 and VS 2012, but there is also an equivalent for EF 4.x.

enter image description here

It allows to generate POCOs already decorated with WCF attributes without having to customize the template.