Replies: 12 comments 29 replies
-
Beta Was this translation helpful? Give feedback.
-
|
I'm currently upgrading to 6x and I ran into an issue with the expression This worked in 5.4. |
Beta Was this translation helpful? Give feedback.
-
|
During migration I discovered this: When I have a var dt = DateTime.UtcNow;
var query = db.GetTable<Person>().Where(p => p.CreatedAt < dt.AddDays(1));Is this on purpose? |
Beta Was this translation helpful? Give feedback.
-
|
It seems that expression extension methods using // I know I'm not supposed to use [SqlQueryDependent] here as the id parameter doesn't actually affect the generated sql
// this is just to showcase the thing
[Sql.Expression("Id = {1}")]
public static bool HasId(this Person person, [SqlQueryDependent] int id)
{
return person.Id == id;
}
// Query
var maybeId = (int?)5;
var queryThatWorks = db.GetTable<Person>().Where(p => maybeId.HasValue ? p.HasId(maybeId.Value) : true);
Console.WriteLine(queryThatWorks.ToSqlQuery().Sql);
// Change maybeId to null to hit the other branch
maybeId = null;
var queryThatProducesError = db.GetTable<Person>().Where(p => maybeId.HasValue ? p.HasId(maybeId.Value) : true);
Console.WriteLine(queryThatProducesError.ToSqlQuery().Sql); |
Beta Was this translation helpful? Give feedback.
-
|
It seems arbitrarily nested It seems that when using both // worked before, but no only seems to allow 1-level deep LoadWith
db.GetTable<Person>()
.Where(p => p.Children.Any(c => c.IsHungry))
.LoadWith(
p => p.Children,
child => child.LoadWith(c => c.Friends) // <-- seems to no longer work
)
.ToArrayAsync();But if I switch the order it seems to work: db.GetTable<Person>()
.LoadWith(
p => p.Children,
child => child.LoadWith(c => c.Friends)
)
.Where(p => p.Children.Any(c => c.IsHungry))
.ToArrayAsync();Are there any side effects to just moving the Minimal reprousing System;
using System.Linq;
using System.Threading.Tasks;
using LinqToDB;
using LinqToDB.Async;
using LinqToDB.Data;
using LinqToDB.Mapping;
using Microsoft.Data.Sqlite;
[Table(Name = "People")]
public sealed class Person
{
[Column, PrimaryKey, Identity]
public int Id { get; set; }
[Column]
public string? Name { get; set; }
[Column]
public int? ParentId { get; set; }
[Association(ThisKey = nameof(Id), OtherKey = nameof(ParentId))]
public Person[] Children { get; set; }
}
public class Program
{
public static async Task Main()
{
using var sqlite = new SqliteConnection("Data Source=:memory:");
await sqlite.OpenAsync();
// Create a linq2db connection
using var db = new DataConnection(
new DataOptions()
.UseDataProvider(LinqToDB.DataProvider.SQLite.SQLiteTools.GetDataProvider())
.UseConnection(sqlite)
);
// Data
await db.CreateTableAsync<Person>();
var grandParentId = await db.InsertWithInt32IdentityAsync(new Person { Name = "Grandparent" });
var parentId = await db.InsertWithInt32IdentityAsync(new Person { Name = "Parent", ParentId = grandParentId });
await db.InsertAsync(new Person { Name = "Child", ParentId = parentId });
// Query
var works = await db.GetTable<Person>()
.LoadWith(p => p.Children, children => children.LoadWith(child => child.Children))
.FirstAsync();
Print(works);
// The order of the LoadWith and Where calls matter
var alsoWorks = await db.GetTable<Person>()
.LoadWith(p => p.Children, children => children.LoadWith(child => child.Children))
.Where(p => p.Children!.Any(c => c.Name == "Parent"))
.FirstAsync();
Print(alsoWorks);
var onlySomewhatWorks = await db.GetTable<Person>()
.Where(p => p.Children!.Any(c => c.ParentId != null)) // <-- maybe messes with the LoadWith expression tree?
.LoadWith(p => p.Children, children => children.LoadWith(child => child.Children))
.FirstAsync();
Print(onlySomewhatWorks);
}
static void Print(Person p)
{
Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(p));
}
}Which prints {"Id":1,"Name":"Grandparent","ParentId":null,"Children":[{"Id":2,"Name":"Parent","ParentId":1,"Children":[{"Id":3,"Name":"Child","ParentId":2,"Children":null}]}]}
{"Id":1,"Name":"Grandparent","ParentId":null,"Children":[{"Id":2,"Name":"Parent","ParentId":1,"Children":[{"Id":3,"Name":"Child","ParentId":2,"Children":null}]}]}
{"Id":1,"Name":"Grandparent","ParentId":null,"Children":[{"Id":2,"Name":"Parent","ParentId":1,"Children":null}]} |
Beta Was this translation helpful? Give feedback.
-
|
I upgraded from version 5.4.1 to 6 and I'm facing a problem where saving doesn't work if I create a nested object This worked in 5.4.1 and doesn't work in 6 Now, instead, I need to do this Please tell me is this the intended behavior or is it really a bug? |
Beta Was this translation helpful? Give feedback.
-
|
In version 6, I encountered a problem that was not present in 5.4.1. I made a small simplified example I also noticed that if I do this Then I stop getting the error. |
Beta Was this translation helpful? Give feedback.
-
|
Hi! I plan to start a new ASP.NET project this week that will use linq2db. |
Beta Was this translation helpful? Give feedback.
-
|
https://github.com/linq2db/linq2db/wiki/Linq-To-DB-6#preview-2-obsoletions
I'm trying to understand how I should update my code. Is there any example in tests? Right now I have a query like that: But UpdateAsync is marked as obsolete. How I supposed to rewrite it? Some examples in migration guide would be appreciated |
Beta Was this translation helpful? Give feedback.
-
|
Use the following await _orderContext.Orders
.InnerJoin(
temp,
(x, y) => x.Id == y.Id,
(x, y) => new
{
Target = x,
Source = y
})
.Set(x => x.Target.ShortId, x => x.Source.ShortId)
.UpdateAsync(ct); |
Beta Was this translation helpful? Give feedback.
-
|
Before 6.x I used a DataOptions instance, opened a transaction and added it to the DataOptions Then I reused the DataOptions instance multiple times like It worked out before 6.x. Now I receive an ORA-604 error. var dataOptions = new DataOptions().UseProvider(providerName: myProviderName)
.UseConnectionString(connectionString: myConnectionString);
using var contextSource = new DataConnection(options: dataOptionsSource);
// Then create a SERIALIZABLE level transaction
using var transactionSource = await contextSource.Connection
.BeginTransactionAsync(isolationLevel: IsolationLevel.Serializable, cancellationToken: cancellationToken);
// Add to dataOptions:
dataOptions = dataOptions
.UseTransaction(dataProvider: contextSource.DataProvider, transaction: transactionSource);Due to the Connection being annotated as obsolete I added
And used the dbConnection but still I have the ORA-604 exception. How can I manage to share/reuse the transaction in 6.x like |
Beta Was this translation helpful? Give feedback.
-
|
Hello! return await (
from lssgst in db.LineServiceStatsGroupStatsTypes
from st in db.StatsTypes.LeftJoin(x => x.Id.RawValue == lssgst.StatsTypeId)
select new StatTypeWithStatsGroupId(
lssgst.StatsTypeId,
st.FullName,
lssgst.LineServiceStatsGroupId,
lssgst.SportId))
.ToListAsync(ct); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Place to discuss Linq To DB 6 migration issues/questions
FAQ:
linq2db.AspNetpackage was renamed tolinq2db.ExtensionsKnown issues:
Beta Was this translation helpful? Give feedback.
All reactions