need custom Set() collection for Update()
See original GitHub issuethis is problem after i make custom FindQuery() https://github.com/linq2db/linq2db/issues/2793
var get = db.T_Table1.FirstOrDefault(x => x.RowId == 1 && x.Code == "code1");
if (get != null)
{
if (true)
{
get.StringValue = "a";
//db.FindQuery(get).Set(x => x.StringValue, get.StringValue).Update();
}
if (true)
{
get.IntValue = 5;
//db.FindQuery(get).Set(x => x.IntValue, get.IntValue).Update();
}
if (true)
{
get.MoneyValue = 1000000;
//db.FindQuery(get).Set(x => x.MoneyValue, get.MoneyValue).Update();
}
//db.FindQuery(get).Set(x => x.StringValue, get.StringValue)
// .Set(x => x.IntValue, get.IntValue)
// .Set(x => x.MoneyValue, get.MoneyValue)
// .Update();
}
since linq2db cannot track changes, i need to collect Changes before do Update()
public class MyUpdate<T> where T : class
{
private IQueryable<T> query { get; set; }
private LinqToDB.Linq.IUpdatable<T> updatequery { get; set; }
public MyUpdate(IQueryable<T> source)
{
query = source;
}
public void Set<TV>(System.Linq.Expressions.Expression<Func<T, TV>> extract, TV value)
{
if (updatequery == null)
{
updatequery = query.Set(extract, value);
}
else
{
updatequery = updatequery.Set(extract, value);
}
}
public void ClearSet()
{
updatequery = null;
}
public int Update()
{
if (updatequery != null)
{
return updatequery.Update();
}
return 0;
}
public override string ToString()
{
if (updatequery == null)
{
return null;
}
else
{
return updatequery.ToString();
}
}
}
with this i can update column i want by condition
var get = db.T_Table1.FirstOrDefault(x => x.RowId == 1 && x.Code == "code1");
if (get != null)
{
var qupdate = new MyUpdate<T_Table1>(db.FindQuery(get));
if (true)
{
get.StringValue = "a";
qupdate.Set(x => x.StringValue, get.StringValue);
}
if (true)
{
get.IntValue = 5;
qupdate.Set(x => x.IntValue, get.IntValue);
}
if (true)
{
get.MoneyValue = 1000000;
qupdate.Set(x => x.MoneyValue, get.MoneyValue);
}
int affected = qupdate.Update();
}
i need feature something like this or more simple for future
Environment details
linq2db version: 3.2.3 Database: PostgreSQL 12.1 .NET Framework: 4.7.2
Issue Analytics
- State:
- Created 3 years ago
- Comments:22 (12 by maintainers)
Top Results From Across the Web
How to create a custom collection that extends on Sets In ...
I want to create a new custom Scala collection from existing Set Collection which I can later extend with some additional functions.
Read more >Add data to Cloud Firestore - Firebase - Google
This guide explains how to use the set, add, or update individual documents in Cloud Firestore. If you want to write data in...
Read more >Add to Update Set Utility Documentation and Custom...
You have custom configurations with dependencies that you wish to automate pushing into update sets. In the saveRecord() function of the ...
Read more >Set custom metadata | Compute Engine Documentation
Click the instance for which you want to update metadata. Click the Edit button at the top of the page. Under Custom metadata,...
Read more >Set up event parameters | Google Analytics 4 Properties
This guide shows you how to set up parameters for recommended events and custom events on your website so you can collect more...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is solution. Don’t even tell someone that I have helped in creating generic repository for linq2db. Worst idea ever. Usage is simple: