We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

OdataV4 Adapter with Backend Autogenerated Guid

Thread ID:

Created:

Updated:

Platform:

Replies:

150496 Jan 9,2020 06:17 AM UTC Jan 13,2020 09:50 AM UTC Angular - EJ 2 3
loading
Tags: Grid
Albert K
Asked On January 9, 2020 06:17 AM UTC


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);
 }

}

Dhivya Rajendran [Syncfusion]
Replied On 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 


Albert K
Replied On 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);
 }




Balaji Sekar [Syncfusion]
Replied On 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. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon