Questions tagged [linq2db]

LINQ to DB is a fast LINQ database access library offering a simple, light, fast, and type-safe layer between your POCO objects and your database.

LINQ to DB is a fast LINQ database access library offering a simple, light, fast, and type-safe layer between your POCO objects and your database.

Architecturally it is one step above micro-ORMs like Dapper, Massive, or PetaPoco, in that you work with LINQ expressions, not with magic strings, while maintaining a thin abstraction layer between your code and the database. Your queries are checked by the C# compiler and allow for easy refactoring.

However, it's not as heavy as LINQ to SQL or Entity Framework. There is no change-tracking, so you have to manage that yourself, but on the plus side you get more control and faster access to your data.

See Wiki for more details.

Code examples and demos can be found here.

183 questions
10
votes
1 answer

Linq2DB Nlog or logging

is there a way to log all linq2DB sql queries that are made to he database with NLog? I cannot find any realistic example. There is something for miniprofiler, but this doesn't help me, because I have not experience with it. pull request…
Franki1986
  • 1,320
  • 1
  • 15
  • 40
8
votes
3 answers

When will connection be closed in case of IEnumerable with using

Suppose I have such pseudo code using some pseudo ORM (ok in my case it's Linq2Db). static IEnumerable GetA() { using (var db = ConnectionFactory.Current.GetDBConnection()) { return from a in db.A select a; } } static B[]…
nikita
  • 2,737
  • 2
  • 20
  • 26
7
votes
3 answers

Executing raw SQL string using linq2db

Using linq2db (https://github.com/linq2db/linq2db) can I execute a raw SQL string and get the result as a dynamic? I'm looking for something like ADO.NET's DBCommand.ExecuteReader or Dapper's Query.
rickythefox
  • 6,601
  • 6
  • 40
  • 62
6
votes
1 answer

Update row with check by linq2db in one atomic operation

MS SQL database table has timestamp field which value changing after update row. Before update I want to check if the row is changed from another service. I can do it by comparing timestamp values from object in memory with value from database…
FireShock
  • 1,082
  • 1
  • 15
  • 25
5
votes
1 answer

How to track Linq2Db add,update,delete events?

How can I track events on adding, updating or deleting entity rows with Linq2Db? I need to recalculate some data in db on this operations, what is the best way? On Entity Framework I use my custom Repository class with custom Add operations. Mabe…
Dmitrij Polyanin
  • 485
  • 5
  • 23
5
votes
2 answers

How to delete multiple rows using LINQ in linq2db Templates based on two tables?

I've two tables Product and user. Now, i want to delete multiple records at a time with a relation like: i want to delete all the products related to particular user. I've delete multiple records code in linq2db Templates using (var db = new…
Chanikya
  • 476
  • 1
  • 8
  • 22
5
votes
3 answers

LinqToDB how to store enum as string value?

Can LinqToDB store the value of an Enum property as the string value of the Enum instead of the integer value? public enum OrderType { New, Cancel } [Table("Orders")] public class Order { [PrimaryKey, Identity] public int OrderId {…
BiaachMonkie
  • 141
  • 1
  • 7
4
votes
3 answers

Left join with grouping via linq2db

I have the following tables class Directory { public long Id { get; set;} public string Path { get; set;} public IEnumerable Files { get; set;} } class File { public long Id { get; set;} public long DirectoryId { get; set;…
Ten
  • 53
  • 1
  • 5
4
votes
2 answers

Create table with Linq to Sqlite (linq2db)

What I'm trying to do is to create a table on the fly, when a connection is opened on an empty database. I've already created the model with Linq to Sqlite and successfully used it with non-empty databases. Now I'm trying to work with "new"…
Bigger
  • 1,807
  • 3
  • 18
  • 28
3
votes
1 answer

Is there a way to reference the same CTE inside a compiled query more than once in Linq2Db?

Consider the following C# code: CompiledQuery.Compile((ctx, someId) => ctx .GetTable() .Where(x => x.SomeId == someId /* complex filtering here */) .AsCte("filtered") .Join( …
b.geor
  • 73
  • 6
3
votes
1 answer

Linq2db: effective way to query hierarchy of objects

I'm using a c# and linq2db and have the following class/tables hierarchy: public class YearlyTemplate { [Column] public int Id { get; set; } public List MonthlyTemplates { get; set;} } public class MonthlyTemplate { …
Grigory Zhadko
  • 1,484
  • 1
  • 19
  • 33
3
votes
1 answer

Can't cast SqlGeography when withdrawing data from DB

I can't get SqlGeography object from MS SQL DB, I use .net core app and linq2db as the provider, but I have an exception: "Can't create 'GIS_CH_DB.sys.geography' type or '' specific type for Geometry." But I'm use var provider =…
3
votes
1 answer

How could i manage multiple database in linq2db

I want to manage multiple database connection in my application.I am using ASP.NET Core & linq2db. For my first database connection i have create below configuration and its working fine. public class DatabaseXSettings : ILinqToDBSettings { …
Muhammad Azim
  • 329
  • 1
  • 2
  • 14
3
votes
3 answers

How to map Oracle database NUMBER to c# bool type in .NET Core?

I have Oracle database table with column of type NUMBER. Due to legacy reasons this column represents boolean such that value 0 represents false and value -1 represents true. I need to map this table to the C# class and thus map this column to bool…
mlst
  • 2,688
  • 7
  • 27
  • 57
3
votes
3 answers

Linq2db insertion with identity not working as expected

To keep working in an application with data from database, I'm using linq2db. The insertion of an object in DB was expected to insert WITH ID if that object has one, and to create new ID in DB for this object if there is no identity. But for now,…
BAndrei
  • 199
  • 2
  • 11
1
2 3
12 13