Print Page | Close Window

OData and IgnoreProperties attribute

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2578
Printed Date: 24-Apr-2024 at 2:06am


Topic: OData and IgnoreProperties attribute
Posted By: tersiusk
Subject: OData and IgnoreProperties attribute
Date Posted: 22-Mar-2011 at 7:46am
Hi

I have an entity base class for all my entities an I have also enabled OData. Now it seems that there are some properties in my EntityBase class that is not supported by OData/WCF data services. I did add the IgnoreProperties attribute to my base class but it seems to be overridden by the generated IgnoreProperties attribute in the IB.Designer file.

How can I add my own IgnoreProperties  attribute?

Regards



Replies:
Posted By: DenisK
Date Posted: 23-Mar-2011 at 2:12pm
Hi tersiusk;

It looks like you will need to customize the T4 template to add the extra properties to the IgnoreProperties attribute.

Please see  http://drc.ideablade.com/xwiki/bin/view/Documentation/Customizing-DevForce-Code-Generation-Template - http://drc.ideablade.com/xwiki/bin/view/Documentation/Customizing-DevForce-Code-Generation-Template  for tutorial on how to customize the T4 template.


Posted By: DenisK
Date Posted: 28-Mar-2011 at 11:14am
For those who are interested, this is how you would override the default T4 template.

public class MyTemplate : DomainModelTemplate {
public MyTemplate(Microsoft.VisualStudio.TextTemplating.TextTransformation textTransformation)
: base(textTransformation) {}
protected override void WriteEntityODataAttributes(EntityTypeWrapper entityType) {
WriteAttribute("IgnoreProperties(" + SafeQuote("EntityAspect") + ", " + SafeQuote("BaseString") + ")");
WriteAttribute("DataServiceKey(" + SafeQuote("CustomerID") + ")");
}
}

This is a very simplified example but it should give the general idea. A feature request has already been submitted to support a metadata buddy class which can be used to override the generated attribute.


Posted By: chuckc
Date Posted: 07-Feb-2012 at 8:50am
Is there any update to IgnoreProperties support?  Any timeline on the metadata buddy class?

Thanks.


Posted By: DenisK
Date Posted: 07-Feb-2012 at 11:39am
Hi chuckc,

This feature request has been put on hold because, since the entity classes are partial classes, we can actually add whatever attributes we want to them. 

For example, in this case, instead of generating the IgnoreProperties attribute to the Customer class in the IB.Designer.cs, we can add it to the partial class in our own Customer.cs

  [IgnoreProperties(@"EntityAspect", @"BaseString")]
  public partial class Customer {
  }

You can still customize the template generation if you require multiple modifications.


Posted By: chuckc
Date Posted: 07-Feb-2012 at 12:13pm
Did you try this?  It doesn't work for me. 

Since there is already an existing IgnoreProperties on the partial class in the generated xxx.IB.Designer.cs file, when you add another IgnoreProperties to the partial in the developer file I get a "Duplicate 'IgnoreProperties' attribute" compile error.

I also already tried [IgnoreDataMember] directly on the offending property, and that didn't seem to work either.  No errors, it just seems to have no effect.

Thanks.


Posted By: DenisK
Date Posted: 07-Feb-2012 at 1:18pm
I did not try this. You are correct. My bad chuckc. I apologize. This was an old post and for some reason, I forgot that the IgnorePropertiesAttribute is generated by DevForce template.

I will re-open the feature request. For now, the workaround is providing your own custom template as shown above.



Print Page | Close Window