New Posts New Posts RSS Feed: Setting IgnorePropertiesAttribute on a generated entity
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Setting IgnorePropertiesAttribute on a generated entity

 Post Reply Post Reply
Author
alexander View Drop Down
Newbie
Newbie


Joined: 13-Feb-2012
Posts: 10
Post Options Post Options   Quote alexander Quote  Post ReplyReply Direct Link To This Post Topic: Setting IgnorePropertiesAttribute on a generated entity
    Posted: 24-Feb-2012 at 1:19am
I'm trying to expose my entity model as an OData service, 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?
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: 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.

Back to Top
alexander View Drop Down
Newbie
Newbie


Joined: 13-Feb-2012
Posts: 10
Post Options Post Options   Quote alexander Quote  Post ReplyReply Direct Link To This Post 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.
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: 29-Feb-2012 at 1:58pm
Thanks for the good suggestion alexander. I've added that to our feature request list.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down