0

I want a generic query for all the tables using linq2db.EntityFrameworkCore

I have 5 things. 1. TableName 2. ColumnaName 3. ColumnValue 4. Where condition column name 5. Where condition column value.

So far what I am trying practically is something like below.

public void update(string entity, string attribute, object value, string whereAttribute, string whereAttributeValue)
{
    projectContext.Set<object>().ToLinqToDBTable().TableName(entity)
        .Where(t => t[whereAttribute] == whereAttributeValue) // This is not working.
        .Set(t => t[attribute], value) // so far it is not giving any build error.
        .Update();
}

but it is not working. how to fix this?

Anonymous Creator
  • 2,968
  • 7
  • 31
  • 77

1 Answers1

2

Linq2db has dynamic properties feature that you probably could use here, but it needs to know entity type:

public void update<TEntity>(string entity, string attribute, object value, string whereAttribute, string whereAttributeValue)
    where TEntity : class
{
    projectContext.GetTable<TEntity>()
        .TableName(entity)
        .Where(t => Sql.Property<TEntity>(t, whereAttribute).Equals(whereAttributeValue))
        .Set(t => Sql.Property<TEntity>(t, attribute), value)
        .Update();
}