Page 1 of 1

Auto add [Key] attribute to primary key field?

Posted: Sun 15 Jan 2012 12:09
by agrei1
Hi,

Is there a way to have the "Key" attribute automatically placed before the primary key properties in all my entities? I've set the "Validation Framework"="DataAnnotations" and note that the "Required" attribute is added to primary keys but the "Key" attribute isn't.

The reason I want it is that Silverlight RIA domain services needs it. I could add it manually but that's a bit of a hassle.

Thanks

Posted: Mon 16 Jan 2012 09:01
by Remco Blok
Hi,

This is a WCF RIA Servies question, not a Devart question. Since you're on the Devart Entity Framework forum, I assume you're using Entity Framework. Your domain service can either derive from DbDomainService when using DbContext or from LinqToEntitiesDomainSerive when using ObjectContext. In either case your Key attribute will be added automatically. This is taken care of by the DbDomainServiceDescriptionProvider or LinqToEntitiesDomainServiceDescriptionProvider attributes that these classes are decorated with. If you must derive from the base DomainService class you can always decorate your domain service with either DbDomainServiceDescriptionProvider or LinqToEntitiesDomainServiceDescriptionProvider attribute manually to have the Key attribute added automatically. See http://code.msdn.microsoft.com/Task-bas ... r-2eb86fab. Note that this Key attribute will not appear in your source code. It is added at runtime. Hope that helps

Remco

Posted: Mon 16 Jan 2012 11:46
by agrei1
Hi,

Thanks for the reply but I've posted this in the wrong forum- it's an EntityDeveloper for nHibernate question so I re-post it there.

Thanks again.