开发者

Linq to Entities: If I DON'T want a property called ID what is the attribute I need to use

开发者 https://www.devze.com 2023-03-16 21:40 出处:网络
I am creating a POCO object for ADO.NET DataServce (they are called WCF DataServices now) The compiler tells me that entities need to have an ID property.

I am creating a POCO object for ADO.NET DataServce (they are called WCF DataServices now) The compiler tells me that entities need to have an ID property.

OK, that's fine but I don't want to call mine ID, I want to call it 'Code'. What attribute do I put on the property 'Code' to tell the service that it is the 'primary key'?

I h开发者_如何学Goave been searching Google for an answer but today I can't seem the guess the right sequence of words


You add an attribute on your POCO class that tells ADO Data Services which property is your Unique Key. Like an example below. You mark the property to use with: DataServiceKey("Id")]. In my case it was "Id". But you should be able to change it to somethign else.

 [DataServiceKey("Id")]
public class Phone
{
    public int Id { get; set; }
    public string Number { get; set; }
    public string Extension { get; set; }
    public string PhoneType { get; set; }
    public int SortOder { get; set; }
}

Key property with different name:

 [DataServiceKey("Code")]
public class Phone
{
    public int Code { get; set; }
    public string Number { get; set; }
    public string Extension { get; set; }
    public string PhoneType { get; set; }
    public int SortOder { get; set; }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消