Base solution for your next web application
Open Closed

Insert in Multiple Table(Parent & Child Table) #7650


User avatar
0
nitinrpatel created

I want to insert data in multiple tables i.e Parent And Child table(Some Fields of Parent Table with Parent Referance) how is it possible in asp.net zero.?


1 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @nitinrpatel

    If this code is running in an AppService method, you can follow an approach like this:

    public async Task Save(){
    {
    	var master = new MasterEntity();
    	master.Name = "Test";
    	
    	await _masterRepository.InsertAsync(master);
    	
    	await CurrentUnitOfwork.SaveChangesAsync();
    	
    	var detail = new Detail();
    	detail.Name = "Detail 1";
    	detail.MasterId = master.Id;
    	
    	await _detailRepository.InsertAsync(detail);
    }
    

    Assuming you are using Integer as the primary key for both entities.