last day (16 days later) » 

11:10 PM
0
Q: entity framework core update column with foreign key reference

ShaggyThis is the simplified version of the table structure I have: [Table("PolicyMapping")] public class PolicyMapping { [Key] public Guid Id { get; set; } public Policy PolicyA { get; set; } public Policy PolicyB { get; set; } public Lookup_Bank Bank { get; set; } } [Tab...

 
I am using services.AddDbContext. So I think its default one. One per request. I am updating the PolicyMapping on Post request.
 
"two different entities with the same Id" - that is your error, which seems somewhat obvious; it's not much of an "identifier" if the value can be duplicated. What is the reasoning for using that value twice?
 
Lets you have a Policy with Rule A & Rule B. In a day, for the first 12 hours Rule A will get executed and after that Rule B will get executed. But you can set up the same rule to get executed for both the times. This is part of the requirement.
 
So, technically "PolicyA" and "PolicyB" can be the same policy, NOT two distinct policies which happen (if the table allowed it) to have the same Id value?
 
@TiesonT. That's right
 
11:10 PM
Worth noting, in your "Solution 1", that dbContext.PolicyMapping.Attach(fromdatabase); is not necessary, since fromdatabase is never in a detached state.
 

  last day (16 days later) »