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
Auto add [Key] attribute to primary key field?
-
- Posts: 25
- Joined: Tue 14 Dec 2010 12:34
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
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