Auto add [Key] attribute to primary key field?

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
agrei1
Posts: 3
Joined: Sun 15 Jan 2012 11:39

Auto add [Key] attribute to primary key field?

Post by agrei1 » Sun 15 Jan 2012 12:09

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

Remco Blok
Posts: 25
Joined: Tue 14 Dec 2010 12:34

Post by Remco Blok » Mon 16 Jan 2012 09:01

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

agrei1
Posts: 3
Joined: Sun 15 Jan 2012 11:39

Post by agrei1 » Mon 16 Jan 2012 11:46

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.

Post Reply