-
QuestionIs there a way to add a ContextExample class [Table("StocklistDownloadInfos")]
public class StocklistDownloadInfo
{
[Column(IsPrimaryKey = true)
public int Id { get; set; }
[Column(Length = 500)]
public string Url { get; set; }
[Column]
public DateTime NextDownloadAt { get; set; }
[Column]
public TimeSpan DownloadInterval { get; set; }
} With // Store TimeSpan as Int64 in the database, inspired by https://stackoverflow.com/a/41979971/4823475.
mappingSchema.SetDataType(typeof(TimeSpan), DataType.Int64);
mappingSchema.SetDataType(typeof(TimeSpan?), DataType.Int64); What we're trying to do is basically adding the await connection
.GetTable<StocklistDownloadInfo>()
.Where(x => x.Id == someId)
.Set(x => x.NextDownloadAt, x => x.NextDownloadAt + x.DownloadInterval)
.UpdateAsync(); This does not work with our current setup and yields the following error:
We're using an Sqlite database to run our tests, so that's where I've encountered it, I haven't tested on other server types. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I don't think we provide such operation out-of-box, but you can add own mapping to sql.
[Sql.Expression("your_custom_sql_here")]
public static DateTime MyAddFunction(DateTime date, TimeSpan interval) => throw new InvalidOperationException("server-side only method");
|
Beta Was this translation helpful? Give feedback.
-
[Sql.Expression("your_custom_sql_here")]
public static DateTime MyAddFunction(DateTime date, TimeSpan interval) => date + interval; In this case it will work on client side as well. |
Beta Was this translation helpful? Give feedback.
I don't think we provide such operation out-of-box, but you can add own mapping to sql.
Expressions.MapBinary
, but I would not recommend it as it will override old behavior and requires function from (1) anyways