【问题标题】:Identity on non-PK property with EFEF 非 PK 属性的身份
【发布时间】:2012-01-15 01:16:15
【问题描述】:

我遇到以下情况,我将 EF 与 IDbSet 实体一起使用,并且我的属性有一个 GUID 作为 PK,但我需要一个拥有自动增量的实体。如果我把key属性放在应该是auto-increment的属性上,属性就不再是GUID PK了。

有谁知道在不开启 PK 的情况下将自动增量属性放入 EF 的任何方法?

namespace Service.Entity.Order
{
    [Serializable]
    public class Order : IEntity
    {
        #region Properties

        public Guid Id { get; set; }
        public DateTime DateImplementation { get; set; }
        public DateTime? DateDelivery { get; set; }

        //Field Auto-Increment
        public int NrOrder { get; set; }

        #endregion

        #region Status

        public int ProcessStatus { get; set; }

        public Status Created { get; set; }
        public Status Approved { get; set; }
        public Status PolicyDefined { get; set; }

        #endregion

        #region RelationShips

        public Client Client { get; set; }
        public User User { get; set; }
        public Representation Representation { get; set; }
        public Contact Contact { get; set; }

        #endregion
    }
}

【问题讨论】:

标签: entity-framework auto-increment


【解决方案1】:

解决方案, 将此属性置于属性之上

[DatabaseGenerated(System.ComponentModel.DataAnnotations.DatabaseGeneratedOption.Identity)]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-02
    • 1970-01-01
    • 2021-10-09
    • 1970-01-01
    • 1970-01-01
    • 2018-07-11
    相关资源
    最近更新 更多