In grid :Lookup customer name using customer-number

I have a grid (orders) that displays customer-number.

I want to display customer-name instead of customer-number,so I need to access customer table and get customer name.
(So this is lookup)

But I have no relationship between the 2 tables on database level (no primar key/foreign key) and my customer dont want to change this.... so is it possible to add some code to the grid and read customer-name from customer table and display name in grid ?

Indeed Radzen needs a relationship at DB level in order to create the corresponding EF Core code. This in turn allows for using $expand (which translates to a SQL JOIN).

Probably you can use this approach to create a new property (CustomerName) and set it from code. Something like this:

First create a new partial class to extend the Order class:

public partial class Order
   public string CustomerName {get; set;}

Then ignore the customer property by extending the EF context that Radzen has generated for your DB.

public partial class <YOUR DB>Context
        partial void OnModelBuilding(ModelBuilder builder)
            builder.Entity<Order>().Ignore(e => e.CustomerName);

Then extend the OrdersController by creating a new partial class and defining the OnOrdersRead method. In that method read the CustomerName property based on the current order CustomerID.

 public partial class OrdersController
      partial void OnOrdersRead(ref IQueryable<Order> items)
          items = items.Select(order => new Order{
              OrderID = order.OrderID,
              CustomerName = yourdbcontext.Customers.First(c => c.CustomerID == order.CustomerID).Name

Then you can add a new column to your Orders data-grid. Set the column Property to CustomerName. You will have to type it as it won't appear in the property dropdown.

1 Like

Thank you very much for your answer, I will try that