Open Saathveegan opened 7 years ago
Hi @Saathveegan,
you can use entities without inheriting them from EntityBase as long as you don't need our generic repositories for them. Could you clarify your update example because I can't determine where 'destination' and 'source' come from ?
Hi,
Thank you for you reply.
Sorry I forgot to rename. it is suppose to be as follwos.
`public void UpdateAccount(AccountDto account) { var accountDb = _repository.Get(account.Id, query => query.Include(b => b.Discounts));
accountDb.Discounts.Clear();
accountDb .Name = account.Name; accountDb .AccountNo = account.AccountNo; accountDb.Discounts. = GetDiscounts(account)
_repository.Update(accountDb); _unitOfWork.SaveChanges();
}`
private IList<Discount> GetDiscounts(AccountDto account) { // Code will be here creating a list of discounts and return. }
I usually clear the list object and add it again. Seems like it is not working in EF core. May be I am doing wrong. Inserting was working fine, updating was the issue.
I do same as Stritof's answer at Stackoverflow (https://stackoverflow.com/questions/4253165/insert-update-many-to-many-entity-framework-how-do-i-do-it).
Regards, Saath
I think that the problem is that you overwrite the existing list with a new list in accountDb.Discounts. Try adding the new elements to the existing list like this : accountDb.Discounts.Add(...) for each element that comes from GetDiscounts() or accountDb.Discounts.AddRange() to add the whole list in one call (not sure if that last method is supported by EF Core, you'll have to test it).
Thank you for your reply. I will try and let you know...
Regards, Saath
I am having POCO classes as follows.
I have created the Discount class with the key of AccountRef & WholesalerRef . Is it OK to create a class without inheriting "EntityBase"?
When I insert a record it is working fine but when update I am getting an error.
I am updating as below.
Could you please let me know there is any workaround to tackle this issue using your repository pattern?
Regards, Saath