Can anyone help me in understanding the above? Don’t understand when to use to what?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
DataKeyProperty is not used by WCF Data Services at all, it’s unrelated (Note that it’s in a different namespace).
DataServiceEntity is only used in WCF Data Services client library. Any class with this attribute will be considered an entity type. This might be useful if you want to materialize results of a query into a client-side class which doesn’t have the key properties on it.
DataServiceKey is used both by client and server libraries. It specifies the names of key properties. Any class with this attribute is considered an entity type. This is the attribute which is used all the time. It is also generated by the code-gen in VS and the command line tool.
In short, if you define a class which should represent an entity (regardless if it’s on the server or client), you should add the DataServiceKey attribute on it and list all the key properties in the attribute’s constructor.
(It is possible to define classes as entities without the attribute, but then the runtime uses heuristics to recognize entity classes, so unless you really need 100% POCO it’s better to use the attribute.)