AutoGenerate Identity Negative PK in EF4

被刻印的时光 ゝ 提交于 2020-01-05 07:30:12

问题


I am using EF 4.4.0.0 and following custom methods for generating identity negative PK:

    private int? GetMinId()
    {
        return Context.ENTITY.Min(c => (int?)c.Id);
    }

    public int GenerateNegativeId()
    {
        var minId = GetMinId() ?? default(int);

        if (0 < minId) return minId * -1;
        if (0 > minId) return --minId;

        return -1;
    }

Could you explain how to AutoGenerate Identity Negative PK ids. (Is it possible?)

Thank you


回答1:


This is not possible, because identity generation happens on the database side. Why do you need this, why can't you just order your rows?



来源:https://stackoverflow.com/questions/13929859/autogenerate-identity-negative-pk-in-ef4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!