1

I'm with the following situation, I'm using EF with IDbSet entities and my property has a GUID as a PK, but I need one of the entities owned an auto-increment. If I put the key attribute on the property that should be auto-increment property is no longer GUID PK.

Anyone know any way to just put an auto-increment property to EF through without turning it on PK?

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
    }
}
Bruno
  • 13
  • 2
  • Does this help? http://stackoverflow.com/questions/6585455/entity-framework-4-1-code-first-auto-increment-field-on-insert-for-non-primary – Wouter de Kort Dec 07 '11 at 14:27

1 Answers1

3

the solution, put this attribute above the property

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

Fernando
  • 436
  • 4
  • 13