Closed
Description
Hello,
is it possible to store the dynamic columns to another dictionary <string, object> that doesn't exist in the entity itself? Our problem is that we have to use a given datastructure but have tables, that differ for each tenant. So we cannot extend the model class with a dictionary and the attribute [DynamicColumnsStore]. Or would it be possible to throw an event when a column ist encountered, that doesnt exist in the given type?
For example:
namespace OracleTest
{
public class Customer
{
public string Guid { get; set; }
public string Name { get; set; }
}
class Test1
{
public Dictionary<string, object> MetaData { get; set; }
public string ConnectionString { get; set; }
public List<Customer> GetCustomer(string name)
{
using (var db = new DataConnection(ProviderName.OracleManaged, ConnectionString))
{
Dictionary<string, string> metaDataDict = new Dictionary<string, string>();
MappingSchema ms = MappingSchema.Default;
var mb = db.MappingSchema.GetFluentMappingBuilder();
mb.HasAttribute<Customer>(new TableAttribute("Customer"));
mb.HasAttribute<Customer>(new ColumnAttribute("name", "name"));
mb.HasAttribute<Customer>(new ColumnAttribute("guid", "guid"));
mb.Entity<Customer>().Property(x => Sql.Property<string>(x, "AdditionalColumn"));
var query = db.GetTable<Customer>().Where(p => p.Name == name);
db.OnDynamicColumnEvent += OnDynamicColumnHandler;
return query.ToList(); ;
}
}
private void OnDynamicColumnHandler(string columnName, object value)
{
MetaData.Add(columnName, value);
}
}
}
Thank you very much.