0

Entity:

public class Crew
{

        [Key, Column(TypeName = "varchar(32)")]
        public string Id { get; set; }

        [Column(TypeName = "varchar(32)")]
        public string Name { get; set; }

        public ulong LeaderId { get; set; }

        public virtual ICollection<CrewMember> Members { get; set; }

        public Crew()
        {
            Members = new HashSet<CrewMember>();
        }

}

public sealed class CrewMember
{

        [Key]
        public ulong Id { get; set; }

        public double TotalCoinsDeposit { get; set; }

        public bool IsOfficer { get; set; }

}

Error: Database operation expected to affect 1 row(s) but actually affected 0 row(s). Data may have been modified or deleted since entities were loaded ` Code:

// This calls Context.SaveChanges() 
await repo.UpdateAsync(crew, x =>
{
    x.Members.Add(new CrewMember
    {
        Id = user.Id,
        IsOfficer = false
    });
});

I have Entity framework 5.0.5

thoo
  • 9
  • 1
  • 2
  • 1
    Provide some code to where this exceptions comes from, and explain what are you trying to do – Nishan Apr 13 '21 at 03:02
  • The code you show doesn't *do* anything. It's just two classes. As said, where does the exception come from? Show that piece of code, including the content of objects, and also the EF version you're using. – Gert Arnold Apr 13 '21 at 07:51
  • *including the content of objects* -- This tiny added snippet still gives no clue. What's the value of `user.Id`? – Gert Arnold Apr 13 '21 at 20:17

0 Answers0