Can DataObjects.NET support SQL identity columns?
While there's lots to like about DataObjects.NET, I've found help resources to be a lean, and can't find a solit example of using DataObjects.NET with RDBMS generated primary keys. It would seem as though D4O won't do inserts against SQL Server unless it's in control开发者_Go百科l of the key.
Has anyone solved this in the wild?
There is no easy way to make DO4 use IDENTITY columns - mainly, because it is designed to rely on bulk key generation (aka HiLo algorithm).
AFAIK, there are no good workarounds here. E.g. DO4 supports custom key generators, but it's pretty complex to develop one relying on IDENTITY column - in fact, it should insert fake records in bulks and remove them further (or rollback a transaction) to work. Taking into account there can be columns with unique constraints, the task becomes pretty complex.
We'll think about implementing this in future.
You can use Key attribute like this:
[Field, Key]
public int Id { get; private set; }
More info: https://help.dataobjects.net/#DataObjects.Net%20v5.0/06-Keys.html
精彩评论