Hello,
We have a service that is inserting a record like this:
// GroupAppService
public GroupDto Add(GroupAddDto dto)
{
if (String.IsNullOrWhiteSpace(dto.Name))
return GroupDto.NullInstance();
var group = dto.ToGroup();
var id = _groupRepository.InsertAndGetId(group);
group.Id = id;//id is always zero
return dto.FromGroup(group);
}
We are calling this service from our controller like this:
// GroupController
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Add(GroupAddViewModel viewModel)
{
if (!ModelState.IsValid)
return View(viewModel);
var dto = new GroupAddDto(viewModel.Name);
var returnedDto = _groupAppService.Add(dto);
if (returnedDto.Id == 0)
return Content($"Group with name {returnedDto.Name} returned id is 0.");//this is hit every time and data is inserted
return RedirectToAction("Index");
}
The information is saved to our table (see attached). But the id returned is always zero. We tried to follow the advice from [https://github.com/aspnetboilerplate/aspnetboilerplate/issues/1387]). Do you know how we can get the ID back of the group inserted?
9 Answer(s)
-
0
Hi,
Which version of ABP do you use on your project ?
-
0
Thanks for the quick reply.
When we encountered the issue we created a sample project to replicate using the latest version from the dev branch of aspnetzero/aspnet-zero (commit sha1 is bb2c66009d859afc5b466dbee228ba9e32bac9fb).
-
0
Hi,
Can you send your project to <a href="mailto:[email protected]">[email protected]</a>, so we can find a faster solution.
Thanks.
-
0
Hello, Sure as long as your email servers can accept a 20mb zip file or larger. Otherwise we may need somewhere to upload this project for you. Let us know if the email does not arrive. Thanks
-
0
Hi,
We didn't get the email. Maybe you can upload it to google drive and share with <a href="mailto:[email protected]">[email protected]</a> ?
Thanks a lot.
-
0
We sent FTP credential information to <a href="mailto:[email protected]">[email protected]</a> this morning, Monday, March 6th, 2017 to access the project.
-
0
Hi,
Thank you, I ave downloaded the project, you can remove the ftp credentials if you like. I will get back to you soon.
-
0
Hi,
I have checked your project and it seems like your Group entity implements IEntity. You need to derive it from Entity instead of implementing IEntity. So your final entity should be like
public class Group : Entity { ...... }
-
0
Thank you so much. This works!