Repository.InsertOrUpdate() insert duplicate principal record in AbpTestBase of one to zero relationships
See original GitHub issueAbpTestBase 3.5 version MVC 5
Description:
I recreate a new UT (AbpTest Base 3.5 version), A:B (1:0-1)
[Table("A")]
public class A : FullAuditedAggregateRoot<long>
{
public virtual B B { get; set; }
}
[Table("B")]
public class B : FullAuditedAggregateRoot<long>
{
[ForeignKey("Id")]
[Required]
public virtual A A { get; set; }
public B()
{
}
}
private readonly IRepository<A, long> _aRepository;
private readonly IRepository<B, long> _bRepository;
public TestClassTests()
{
_aRepository = LocalIocManager.Resolve<IRepository<A, long>>();
_bRepository = LocalIocManager.Resolve<IRepository<B, long>>();
}
[TestMethod()]
[UnitOfWork]
public void BTest()
{
var a = new A();
_aRepository.InsertOrUpdate(a); //will insert a A record to A-tables
var b = new B();
b.A = a;
var tempB = _bRepository.InsertOrUpdate(b); //will insert A to A-tables and B to B-tables, there are two A records in A-tables.
}
Question: _bRepository.InsertOrUpdate(b); //will insert A to A-tables and B to B-tables, there are two A records in A-tables.
Issue Analytics
- State:
- Created 6 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Duplicate Record in one to one relationship when ...
i have a one to one relationship between two entity and whn i want set navigation property add duplication record tu my table....
Read more >MySQL insert on duplicate update for non-PRIMARY key
This is the query: UPDATE my_table SET unique_name = 'one', update_datetime = NOW() WHERE id = 1; INSERT INTO my_table SELECT 1, 'one',...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@muzizongheng thanks for sharing the project. Unit test methods are not unit of work. So, change your test class like below;
If you place this code in an application service, it will be unit of work by default and you will not have such a problem.
I could not reproduce this.
But if you want a method to be grouped in one
UnitOfWork
, mark it asvirtual
: