Pomelo.EntityFrameworkCore.MySql icon indicating copy to clipboard operation
Pomelo.EntityFrameworkCore.MySql copied to clipboard

Dynamic columns support

Open ChrisProlls opened this issue 6 years ago • 3 comments

For one of our client, we need to use the advanced MariaDb / MySql capability : dynamic columns declaration with BLOB. Is that possible with your EF Core connector ? For reference : https://mariadb.com/kb/en/dynamic-columns/

ChrisProlls avatar Feb 05 '20 13:02 ChrisProlls

That feature is not supported and is unlikely to be introduced. With the little information that you've provided you could possibly implement IRelationalTypeMappingSourcePlugin to store your dynamic data in a JSON column.

mguinness avatar Feb 05 '20 18:02 mguinness

We might take a look at it when we revise the JSON support, because both concepts share similarities.

@ChrisProlls Do you have some sample code how you would expect this to be used?

lauxjpn avatar Feb 05 '20 19:02 lauxjpn

@mguinness thanks for you exemple, but this implementation doesn't use the dynamic columns feature of MariaDB like COLUMN_GET for querying.

The main advantages about dynamic columns are the reading part : all data are stored in a BLOB column, but you can query the dynamic column like they are classic column. Not sure if this can be translated easily from LINQ query...

Let try some example

public class Order {
  public int Id { get; set; }
  public string Title { get; set; }

  public IDictionnary<string, object> Values { get; set; }
}

And in my OnModelCreating

builder.Entity<Order>.HasDynamicColumns(order => order.Values)

This should tell to the provider that Values should be translated to the BLOB column. Then, when created an order :

var order = new Order { Title = "Test" }

order.Values.Add("first_dyn_column", "dynamic_value");
order.Values.Add("first_dyn_column_2", 1);

During creation of my order, Values should be translated to my BLOB column. And for querying

context
    .Set<Order>()
    .Where(order => order.Values["first_dyn_column"] == "dynamic_value")

ChrisProlls avatar Feb 13 '20 13:02 ChrisProlls