Print Page | Close Window

Setting IgnorePropertiesAttribute on a generated entity

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=3295
Printed Date: 13-May-2026 at 11:35am


Topic: Setting IgnorePropertiesAttribute on a generated entity
Posted By: alexander
Subject: Setting IgnorePropertiesAttribute on a generated entity
Date Posted: 24-Feb-2012 at 1:19am
I'm trying to expose my entity model as an OData service, http://drc.ideablade.com/xwiki/bin/view/Documentation/odata-enable - following your instructions . However, when I got to the "Calling your service" part, I got a "Request Error" instead of the proper response. I enabled debugging output, and found that it is caused by some TimeSpan properties on one of my entities, resulting in an error like the following:
The property 'InTime' on type 'My.DataModel.Schedule' is not a valid property. Make sure that the type of the property is a public type and a supported primitive type or a entity type with a valid key or a complex type.
Fair enough. I figured I'd hide these from the DataService using the IgnorePropertiesAttribute on my entity and expose them as something else (such as Ticks) using a calculated property. Thus I created a partial class implementation of my class, like so:
[IgnoreProperties( @"InTime", @"OutTime" )]
partial class Schedule
{
    // TODO: Implement calculated In-/OutTime properties
}
However, when I attempt to compile this, I get this error:
Duplicate 'IgnoreProperties' attribute
Looking at the generated Schedule class, it already has an IgnorePropertiesAttribute, like this:
[IgnoreProperties(@"EntityAspect")]
public partial class Schedule : IbEm.Entity {
}
So, what do I do? Can I hook into the IgnoreProperties generation by just setting a property in the EDMX file, or is there some other way I have to do this?
http://drc.ideablade.com/xwiki/bin/view/Documentation/odata-enable -



Replies:
Posted By: DenisK
Date Posted: 24-Feb-2012 at 3:03pm
Hi alexander,

For the time being, you can override the code generation by overriding the default T4 template. A feature request has been submitted for this to be supported without messing with the code generation.

See  http://www.ideablade.com/forum/forum_posts.asp?TID=2578&title=odata-and-ignoreproperties-attribute - http://www.ideablade.com/forum/forum_posts.asp?TID=2578&title=odata-and-ignoreproperties-attribute  for my response to another customer with the same issue.


Posted By: alexander
Date Posted: 29-Feb-2012 at 12:48am
Thank you, I guess I will have to resort to that.

For the future, though, you might consider letting people set that they want properties ignored directly in the settings for that property. I can tell you've already managed to hook into the EDMX editor, seeing how there are properties under a "DevForce Code Generation" category. Just add a "Ignore in OData" or something of that sort in there.


Posted By: DenisK
Date Posted: 29-Feb-2012 at 1:58pm
Thanks for the good suggestion alexander. I've added that to our feature request list.



Print Page | Close Window