自动生成的身份在EF4负PK自动生成、身份、PK

2023-09-07 16:24:32 作者:我丑你耐我何

我使用的EF 4.4.0.0及以下自定义方法生成的身份负面PK:

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;
    }

你能不能解释一下如何为自动生成身份负面PK IDS。 (这可能吗?)

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

感谢您

推荐答案

这是不可能的,因为身份的产生发生在数据库端。为什么你需要这个,为什么你就不能为了你行?

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?