AutoGenerate Identity Negative PK in EF4

2019-08-01 06:21发布

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条回答
爷的心禁止访问
2楼-- · 2019-08-01 06:53

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?

查看更多
登录 后发表回答