CustomAdaptor does not allow composite keys

When using the Custom Adaptor for the grid to perform Entity Framework Core operations, I do not have access to the keys for my entity.  

1. Is there a way to get all primary keys in my Custom Adaptor?

2. Why can the grid not have a built in Entity Framework Adaptor for server side projects that does all of this work automatically?

3. If the grid can't automatically use Entity Framework Provider to perform CRUD directly, then is there a generic Adaptor that I can use instead of making one for each table I use in my edit grids?  This seems like a lot of extra effort and maintenance when the grid should be able to do CRUD through EF Core automatically.

<GridColumn Field=@nameof(T_TEMP.Key1) HeaderText="Key 1" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="180" AllowEditing="false"></GridColumn>
<GridColumn Field=@nameof(T_TEMP.Key2) HeaderText="Key 2" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="180" AllowEditing="false"></GridColumn>
public override async Task<object> RemoveAsync(DataManager dataManager, object value, string keyField, string key)
{     
  //keyField only has the first column and key is null.  Value is just the value for Key1.
  db.Remove(db.T_TEMP.Where(a => (a.Key1== (value as T_TEMP).Key1) && (a.Key2== (value as T_TEMP).Key2)).FirstOrDefault());
  await db.SaveChangesAsync();   return Task.Run(() =>   {     return value;   }); }

3 Replies 1 reply marked as answer

RN Rahul Narayanasamy Syncfusion Team July 17, 2020 02:02 PM UTC

Hi Paul, 
 
Greetings from Syncfusion. 
 
We have validated your queries with the provided information. From your shared information, you want use multiple primary keys in Grid. Currently we don’t have support for multiple primary key column in Grid. But we have considered this requirement as a feature and logged a feature task “Provide multiple primary key column support in Grid” for this and added to our feature request list. Based on specific parameters including product vision and technological feasibility we will implement this feature. This will be available in any of our upcoming releases.   
 
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.   
 

Query: Is there a way to get all primary keys in my Custom Adaptor? 

Yes, you can get the primary key field names by using GetPrimaryKeyFieldNames method of the Grid. find the below API link for your reference. 


Query: Why can the grid not have a built in Entity Framework Adaptor for server side projects that does all of this work automatically? 

From your query, you want an adaptor for consuming date from Entity framework and perform other Grid operations(paging, sorting, filtering, etc). For this we suggest you to use the CustomAdaptor concept to achieve your requirement. 

Reference

Query: then is there a generic Adaptor that I can use instead of making one for each table I use in my edit grids? 

You want to use same CustomAdaptor(Generic Adaptor) for multiple tables. Yes, you can achieve your requirement by using CustomAdaptor as a Component. Here, we can define the CustomAdaptor component as Generic one and use that component inside various Grid / components. Refer the below code example.   


[Index.razor] 
<SfGrid TValue="Order" AllowPaging="true" EnableHover="false" AllowSorting="true"> 
    <GridPageSettings PageSize="5"></GridPageSettings> 
    <SfDataManager Adaptor="Adaptors.CustomAdaptor"> 
        <CustomComponent T="Order" Details="Orders"></CustomComponent> 
    </SfDataManager> 
    <GridColumns> 
….  
   </GridColumns> 
</SfGrid> 
 
[Test1.Razor] 
 
<SfGrid TValue="Employee" AllowPaging="true" EnableHover="false" AllowSorting="true">    <GridPageSettings PageSize="5"></GridPageSettings>    <SfDataManager Adaptor="Adaptors.CustomAdaptor">        <CustomComponent T="Employee" Details="Employees"></CustomComponent>    </SfDataManager>    <GridColumns>. . . . ..     </GridColumns></SfGrid>

[AdaptorComponent.Razor] 
 
@typeparam T @inherits DataAdaptor<T> <CascadingValue Value="@this">    @ChildContent</CascadingValue> @code {    [Parameter]    [JsonIgnore]    public RenderFragment ChildContent { getset; }     [Parameter]    public List<T> Details { getset; }     // Performs data Read operation    public override object Read(DataManagerRequest dm, string key = null)    {         IEnumerable<T> DataSource = (IEnumerable<T>)Details.Skip(dm.Skip).Take(dm.Take);. . . . . . . . .        return dm.RequiresCounts ? new DataResult() { Result = DataSource, Count = count } : (object)DataSource;    }}

In above example, we have used two different grid with same custom adaptor component. Similar way you can define the Generic CustomAdaptor component.   

Kindly download the sample from below . 


Reference

Please get back to us if you need further assistance. 

Regards, 
Rahul 



BO boucher October 18, 2020 09:19 PM UTC

Thank you for this answer but in the "CustomComponent.razor"

you give only this méthode : public override object Read(DataManagerRequest dm, string key = null)

can you give us the 3 others methodes ? ( Insert, Remove, Update ) 

public override object Remove(DataManager dataManager, object value, string keyField, string key)
{
     // need to find in Details list of type T  where keyFiled (Id)  is equal of value (3)
     //  but do not kwow howto ? may i need to use system.reflexion ? 

     Details.remove(findresult) 
}


public override Object Insert(DataManager dataManager, object value, string key)
public override object Remove(DataManager dataManager, object value, string keyField, string key)
public override object Update(DataManager dataManager, object value, string keyField, string key)






RN Rahul Narayanasamy Syncfusion Team October 26, 2020 03:59 AM UTC

Hi Boucher, 
 
Greetings from Syncfusion. 
 
Query: you give only this méthode : public override object Read(DataManagerRequest dm, string key = null) can you give us the 3 others methodes ? ( Insert, Remove, Update ) 
 
Based on your request we have prepared a sample with other methods(Insert, Remove, Update) of CustomAdaptor. Find the below sample for your reference. 
 
 
Note: To bind the data to Grid, kindly change the connectionstring of Northwnd.MDF file in App_Data filder in the OrderContext.cs file.   
 
Reference: 
 
Please let us know if you have any concerns. 
 
Regards, 
Rahul 
 


Marked as answer
Loader.
Up arrow icon