Lost
Lost

Reputation: 13655

ServiceStack ORMLIte : Id is necessary

I read on couple of articles that while using ORMLite, our objects must have Id property. One of the article is here:

https://code.google.com/p/servicestack/wiki/OrmLite

However, I created a class without Id property and tried serializing and deserializing it and ORMLite did it without any problems. So what feature exactly necessitates the Id property?

Upvotes: 0

Views: 651

Answers (1)

mythz
mythz

Reputation: 143399

The are several API's in OrmLite which rely on a primary key which will be either:

  • A property annotated with the [PrimaryKey] attribute
  • A property named Id
  • Otherwise the first property is considered to be the primary key

Some of OrmLite API's that rely on a primary key is:

  • db.Update(entity) - updates all fields except the primary key which is used as a filter
  • db.Delete(entity) - uses the primary key as a filter
  • db.SingleById(id) - uses the primary key as a filter

Upvotes: 1

Related Questions