- Home
- Forum
- Angular - EJ 2
- OdataV4 Adapter with Backend Autogenerated Guid
OdataV4 Adapter with Backend Autogenerated Guid
I would like to know how to setup a ODataV4 Adaptor where the PrimaryKey is generated by the backend server (Asp.net Core 2.2) upon adding and saving a record to the Grid. How can I achieve this ? At the moment the asp.net OdataController is alway receiving a null User object when the UUID is not initialized on the Client end (angular).
public User
{
[Key]
public Guid UUID {get;set;} // PrimaryKey
public string Name {get;set;}
public DateTime DoB {get;set;}
}
[ODataRoutePrefix("Users")]
public class UsersController : ODataController
{
private readonly IDatabase _db;
public UsersController(IDatabase db)
{
_db = db;
}
// ......
[HttpPost]
[ODataRoute()]
public IActionResult Post([FromBody] User user)
{
// Issue where user class is always null if the UUID property is not initialized on the client end (angular)
// How do I achieve creation of the UUID on the server end
_db.AddUser(user);
return Created(user);
}
}
SIGN IN To post a reply.
3 Replies
DR
Dhivya Rajendran
Syncfusion Team
January 10, 2020 06:40 AM UTC
Hi Albert,
Thanks for contacting us.
To perform CRUD actions in Grid ,we need to set primary key column.
If you have defined the column in client end(angular), i.e.,(inside the <e-column> tag or column property), please refer the below documentation link to set primary key.
If you are using auto generated column in the client end(angular), please refer the below link to set the primary key field in Grid.
If you still faced any problem while performing crud actions then share the Grid code and network tab details for further validation.
Regards,
R. Dhivya
AK
Albert K
January 10, 2020 06:52 AM UTC
Hi,
The only way I can get this working is to initialize the UUID property to a empty value, ie "00000000-0000-0000-0000-000000000000" on the client (angular). On the server end, I have to initialize the Guid. Hope that is the the correct approach.
[HttpPost]
[ODataRoute()]
public IActionResult Post([FromBody] User user)
{
user.UUID = Guid.NewGuid();
_db.AddUser(user);
return Created(user);
}
BS
Balaji Sekar
Syncfusion Team
January 13, 2020 09:50 AM UTC
Hi Albert,
Thanks for your update.
Yes. That is a correct approach. To handle CRUD operations in backend, grid just requires a unique value for each row. So that grid can match the value in the server side and store the changes in database.
Please get back to us if you need further assistance.
Regards,
Balaji Sekar.
SIGN IN To post a reply.
- 3 Replies
- 3 Participants
-
AK Albert K
- Jan 9, 2020 06:17 AM UTC
- Jan 13, 2020 09:50 AM UTC