If a field is declared on an interface and marked with Field attribute, then that field cannot have the Field attribute on the class (PostSharp says it can only be defined once).

The problem is that you then can't apply an index on the class that uses this field =(


Updated at 18.05.2010 4:51:45

Also, if InterfaceB inherits from InterfaceA, then you can't apply an index on InterfaceB that uses a field that is defined on InterfaceA


Updated at 20.05.2010 20:15:31

[quote="mahdness":1e0ujdgf]If a field is declared on an interface and marked with Field attribute, then that field cannot have the Field attribute on the class (PostSharp says it can only be defined once).

The issue is fixed, see nightly builds.

From now, you can mark a property with FieldAttribute both in interface and in implementors, the only requirement is that both attributes must have the same settings ('Length', 'Nullability', 'Scale', 'Precision' & 'LazyLoad') whereas 'Indexed' setting might differ.[/quote:1e0ujdgf]

could you please update the 4.3 RC with this fix (for VS2010)? latest version does not support it =(

thanks


Updated at 21.05.2010 23:14:02

just to be precise... i wasn't only talking about defining an index using [Field(Indexed=true)].

I was talking about applying [Index("PropertyA", "PropertyB", "PropertyC")] on a class ClassX where:

  • PropertyA is defined on ClassX only

  • PropertyB is defined on InterfaceY

  • PropertyC is defined on InterfaceZ, and InterfaceY : InterfaceZ

so...

[Index("PropertyA", "PropertyB", "PropertyC")] class ClassX : Entity, InterfaceY, InterfaceZ { PropertyA get; set; PropertyB get; set; PropertyC get; set; }

interface InterfaceY : InterfaceZ { PropertyB get; set; }

interface InterfaceZ : IEntity { PropertyC get; set; }

This thread was imported from our support forum. The original discussion may contain more detailed answer.

asked May 18 '10 at 04:50

ara's gravatar image

ara
395868791

olorin wrote: I'm also interested in a fix for this.

See viewtopic.php?f=29&t=5855&p=14412#p14411

(May 18 '10 at 04:50) Editor Editor's gravatar image

One Answer:

Hi there,

mahdness: 1. First case (interface, implementor & index) Try using the following syntax (as a temporary workaround, the issue is in work):

[Index("Name", Unique = true, Name = "IX_NAME")]
class Animal : Entity, IHasName {
...
  1. Second case (multi-field index built on fields declared in different classes) There is no workaround for this, some changes must be done to Model builder instead.

olorin: The issue is in work.


If a field is declared on an interface and marked with Field attribute, then that field cannot have the Field attribute on the class (PostSharp says it can only be defined once).

The issue is fixed, see nightly builds.

From now, you can mark a property with FieldAttribute both in interface and in implementors, the only requirement is that both attributes must have the same settings ('Length', 'Nullability', 'Scale', 'Precision' & 'LazyLoad') whereas 'Indexed' setting might differ.


Alex, the original message was about the possibility to mark an implemented property with [Field(Indexed = true)] attribute. The feature was implemented. All other field settings (see my previous post for the whole listing) can't be overridden as they affect the corresponding database column properties.


The scenario you described should work in the current code base, whereas another one where an index which contains one or more inherited fields is defined (described here: http://code.google.com/p/dataobjectsdot ... ail?id=353) is still unsupported.

As I've said earlier, it requires some noticeable changes to be applied to the Model builder code base, therefore I'm afraid that we can implement this only in 4.3.1 branch.

answered May 18 '10 at 09:43

Dmitri%20Maximov's gravatar image

Dmitri Maximov
22111211

Guys, see the original message. It's necessary to implement different behavior allowing to inherit [Field] settings from interface declaration.

(May 18 '10 at 09:43) Alex Yakunin Alex%20Yakunin's gravatar image

olorin wrote: Well as long as we can apply [Field] attribute to interface and to implementing class for the same property, that's ok for me.

(May 18 '10 at 09:43) Editor Editor's gravatar image
(May 18 '10 at 09:43) Alex Yakunin Alex%20Yakunin's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA