New Posts New Posts RSS Feed: OData and IgnoreProperties attribute
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Forum LockedOData and IgnoreProperties attribute

 Post Reply Post Reply
Author
tersiusk View Drop Down
Newbie
Newbie
Avatar

Joined: 03-Nov-2010
Posts: 20
Post Options Post Options   Quote tersiusk Quote  Post ReplyReply Direct Link To This Post Topic: OData and IgnoreProperties attribute
    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
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post 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.



Edited by DenisK - 23-Mar-2011 at 2:15pm
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
chuckc View Drop Down
Groupie
Groupie


Joined: 27-Feb-2010
Posts: 54
Post Options Post Options   Quote chuckc Quote  Post ReplyReply Direct Link To This Post Posted: 07-Feb-2012 at 8:50am
Is there any update to IgnoreProperties support?  Any timeline on the metadata buddy class?

Thanks.
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
chuckc View Drop Down
Groupie
Groupie


Joined: 27-Feb-2010
Posts: 54
Post Options Post Options   Quote chuckc Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down