question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Loading backreference not working

See original GitHub issue

Not working when trying to load a backreference (IEnumerable<object>). Normal references work with this version of linq2db but when trying to load a backreference it simply doesn’t load anything. On VS output window the query doesn’t have the joins on that backreference.

var q = _myDB.MYTABLE .LoadWith(x => x.MYBACKREFERENCECOLLECTION) .Where(x => x.Active) .OrderBy(x => x.Date);

Environment details

Linq To DB version: 3.6.0

Database (with version): SQLServer 2019

ADO.NET Provider (with version): System.Data.SqlClient 4.8.3

Operating system: Windows

.NET Version: .Net6

Issue Analytics

  • State:closed
  • Created 5 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
iColdoCatalincommented, May 2, 2023

Just made a simple test similar to yours and works with same version… I’m gone try and find the issue into my code then. Thanks for helping.

0reactions
MaceWinducommented, May 2, 2023

Just tested it with 3.6.0 and everything works for me. Could you provide similar example where it doesn’t work for you?

using LinqToDB;
using LinqToDB.Data;
using LinqToDB.DataProvider.SQLite;
using LinqToDB.Mapping;
using System.Diagnostics;

internal class Program
{
	static void Main()
	{
		var dbName = "test.sqlite";
		if (File.Exists(dbName))
		{
			File.Delete(dbName);
		}
		using (File.Create(dbName))
		{
		}
		using var db = new DataConnection(SQLiteTools.GetDataProvider(ProviderName.SQLiteClassic), $"Data Source={dbName}");
		DataConnection.TurnTraceSwitchOn(TraceLevel.Verbose);
		db.OnTraceConnection += t => Console.WriteLine(t.SqlText);

		db.CreateTable<MainTable>();
		db.CreateTable<ChildTable>();

		db.Insert(new MainTable() { MAId = 1, Active = true, Date = DateTime.Now });
		db.Insert(new ChildTable() { DvmaMAId = 1 });

		var data = db.GetTable<MainTable>()
			.LoadWith(e => e.ICDeliveDVMA1A17459A)
			.Where(x => x.Active)
			.OrderBy(x => x.Date)
			.ToArray();

		if (data[0].ICDeliveDVMA1A17459A.Count() != 1)
		{
			throw new InvalidOperationException();
		}
	}
}


[Table]
sealed class MainTable
{
	[Column]
	public int MAId { get; set; }
	[Column]
	public bool Active { get; set; }
	[Column]
	public DateTime Date { get; set; }

	[Association(ThisKey = "MAId", OtherKey = "DvmaMAId", CanBeNull = true)]
	public IEnumerable<ChildTable> ICDeliveDVMA1A17459A { get; set; } = null!;
}

[Table]
sealed class ChildTable
{
	[Column]
	public int DvmaMAId { get; set; }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Regex backreference not working [closed]
I tried with this editor but the backreference does not work as I expect. Why does the backreference to the first capture group...
Read more >
loading back-reference groups "shortcut"
I'm looking for a shortcut for loading back-reference groups using the same separator. Such a beast may not exist but it would be...
Read more >
Controlling deferred loading of back reference list fields for ...
Deferred loading of a back reference list field may cause problems for a hook or script. This may happen if the hook or...
Read more >
Illegal back reference when trying to delete \1
You can't use \1 as a back reference to what matched in a separate pattern match. I see you're using the pattern in...
Read more >
back reference details to drawing not working
I have drawn a detail marker (a sourced marker) and when i have placed that on the drawing - i am not able...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found