1. Try using [PrimaryKey(Generator = PrimaryKeyType.Identity)] for you primary key
2. If that doesn't work, you'll need to show us what "_activityPerfomedRepository.Create(activityPerformed);" does. --- Patrick Steele http://weblogs.asp.net/psteele On Thu, Mar 3, 2011 at 8:45 AM, Christian Axelsson <[email protected]> wrote: > Hello, > > > > I have written a few AR classes using the repository pattern suggested at > [1]. > > For example I have: > > > > [ActiveRecord(Table = "ActivityPerformed", Schema = "dbo")] > > public class ActivityPerformed : IAggregateRoot > > { > > [PrimaryKey] > > public virtual int Id { get; private set; } > > > > [Property(NotNull = true)] > > public virtual DateTime Date { get; set; } > > > > [BelongsTo(Column = "ContractID", NotNull = true)] > > public virtual Contract Contract { get; set; } > > > > [Property(NotNull = true)] > > public virtual float Quantity { get; set; } > > } > > > > However when I try to create a new instance like this: > > > > var activityPerformed = new ActivityPerformed() > > { > > Contract = > activityPerfomViewModel.Contract, > > Date = activityPerfomViewModel.Date, > > Quantity = quantity > > }; > > > > using (new SessionScope(FlushAction.Auto)) > > { > > _activityPerfomedRepository.Create(activityPerformed); > > } > > > > AR will throw an exception about inserting duplicate row because the ID, > defaulted to 0, is already exist. > > The Id column in the database is an auto incrementing numeric on a SQL > Server database and I’ve tried specified both PrimaryKeyType.Native and > PrimaryKeyType.Identity but I get the same result. > > > > Any help is appreciated. > > > > /Christian > > > > > > [1] > http://fatagnus.com/using-the-repository-pattern-with-activerecord-from-castle/ > > -- > You received this message because you are subscribed to the Google Groups > "Castle Project Users" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/castle-project-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Castle Project Users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.
