You can use the GenerateId method in the LocalKeyGenerator or KeyGenerator classes to generate an ID when creating a new object for which you require a primary key or surrogate key.
This method in the LocalKeyGenerator class generates a unique ID for the package on the local device:
public static long GenerateId()
This method in the KeyGenerator class generates a unique ID for the same package across all devices:
public static long GenerateId()