Change Type of SqlExpression

I have a SqlExpression<T1>, that joins T1 and T2 and extract some data from both of them.
If I wanted to use that to update some record of T1, I can do the following:

_db.UpdateOnly(() => new T1{ Field= "foo" }, q); // q is my SqlExpression

I can’t do that for T2 tho:

_db.UpdateOnly(() => new T2{ Field= "foo" }, q);

In the second case the generic type is wrong, since the query is SqlExpression but updateFields is of type T2.

Can I change the type of the SqlExpression? Or can you make an Update[Only][Async] overload that accept IUntypedSqlExpression or ISqlExpression?

No you can’t change the source table type of the SqlExpression.

I’ve just added overloads accepting a SQL whereExpression and DB params in this commit which you can access from a typed SqlExpression<T> using q.WhereExpression and q.Params.

This change is available from v5.4.1 that’s now available on MyGet.

I’m sorry but I don’t understand how this can help me. What I was asking is something like

_db.UpdateOnly<TModel, TQuery>(Expression<Func<TModel>>, SqlExpression<TQuery>)

My use case is that I have a query built with OrmLite, from which I have to update 2 tables, which both of them are included in the FROM clause.

I’m not adding overloads for the proposed unintuitive and niche API, the API added lets you use any custom Where expression and db params.

Have you tried calling it using q.WhereExpression and q.Params as I’ve suggested? It extracts the WhereExpression and DB Params the same as what’s used when passing in SqlExpression<T>.

If it doesn’t do what you need you’d need to re-create the expression using the alternative table you want.

What I was asking was an UPDATE FROM: https://stackoverflow.com/a/2334741/3494407

I wouldn’t define that as a niche API, but I still understand that is a performance optimization rather than a mandatory feature.

Anyway, i’ll solve that in another way, thank you!