interface IPerson defines (persistent) Name [string] property. class Person implements IPerson

should the [Field] attribute be declared on IPerson.Name or Person.Name? is there a difference? what about when multiple classes implement IPerson

postsharp won't allow both


Updated at 16.01.2010 8:55:48

what about [Index] attribute?


Updated at 16.01.2010 22:38:24

I don't like this limitation.... I would prefer to be able to apply [Field] and [Index] both the interface and the class, so that when I look at the code, I can know what's going on (without having to reference the interface, or reference a class implementation). It would be fine if one of the applications had no effect (i.e. it is just there for readability)


Updated at 18.01.2010 21:42:48

That's fine.

I just don't want to be forced to write the following:

[Index("Name")]
interface IPerson : IEntity
{
  [Field]
  string Name { get; set; }
}

class Person : Entity, IPerson
{
  string Name { get; set; }
}

I don't want to look at the Person class and begin to wonder: "Why didn't my developer mark Name as a persistent field? And why didn't he index it!!"

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

asked Jan 16 '10 at 08:54

ara's gravatar image

ara
395878791


One Answer:

[Field] must be applied to both class and interface property. AFAIK model build will fail, if [Field]s there won't be compatible (different type, etc.).

[Index] must be applied on interface only. Its re-applicaiton on class level must lead to an exception (~ the same index name).


> To apply index on interface property, the interface property must be marked with [Field]

It seems I really made a mistake - just checked examples from Xtensive.Storage.Tests project (it's enough to search for IEntity usage there), and all of them use the same pattern.

> I would prefer to be able to apply [Field] and [Index] both the interface and the class...

We'll think about fixing this.

Issue: http://code.google.com/p/dataobjectsdot ... ail?id=583

answered Jan 16 '10 at 17:19

Alex%20Yakunin's gravatar image

Alex Yakunin
29714412

postsharp is throwing build exception if I apply [Field] to both interface and class property

"PostSharp: Multiple [FieldAttribute] attributes are applied to 'String Person.Name', but there must be a single one."

(Jan 16 '10 at 17:19) ara ara's gravatar image

To apply index on interface property, the interface property must be marked with [Field], otherwise the following exception is thrown:

System.ArgumentException : Item with key 'FirstName' was not found.

(FirstName is the name of the property)

(Jan 16 '10 at 17:19) ara ara's gravatar image

What do you think about:

  • [Field(Implementation = true)]

  • [Index("IndexName", Implementation = true)]

They'll be optional. Their absence means field is regular or index absents (must not be created).

(Jan 16 '10 at 17:19) Alex Yakunin Alex%20Yakunin's gravatar image

Ok - than we'll implement this this way. Our goal is to have a single definition. Repetitive "reference" definitions are ok, but they must not contain any details.

(Jan 16 '10 at 17:19) 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

Subscription:

Once you sign in you will be able to subscribe for any updates here

Tags:

×574

Asked: Jan 16 '10 at 08:54

Seen: 2,579 times

Last updated: Jan 16 '10 at 08:54

powered by OSQA