简体   繁体   中英

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 controll 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. Eg 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM