linq2db

linq2db bulkcopyasync without error but no data inserted in the database

非 Y 不嫁゛ 提交于 2021-02-11 12:24:37
问题 I am using linq2db .NET Core library to bulk insert a collection. This code can be executed without error but there is no data in the database. There are 2000 person object in persons list object. Person object has already identity in it. using (var db = SqlServerTools.CreateDataConnection(connstring) { await db.BulkCopyAsync(new BulkCopyOptions { KeepIdentity = true, TableName = "[Persons].[Person]" }, persons); } Person table in in Persons schema. I have also tried with BulkCopy which can

Linq2db: effective way to query hierarchy of objects

泪湿孤枕 提交于 2021-01-05 11:09:57
问题 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<MonthlyTemplate> MonthlyTemplates { get; set;} } public class MonthlyTemplate { [Column] public int Id { get; set; } [Column] public int YearlyTemplateId { get; set; } public YearlyTemplate YearlyTemplate{ get; set; } public List<DailyTemplate> DailyTemplates { get; set;} } public class DailyTemplate { [Column] public int Id { get; set; }

How to create database in Microsoft SQL Server using linq2db by code first approach in .NET CORE 2.2

安稳与你 提交于 2020-01-22 02:31:13
问题 Created new project in .net core 2.2 and installed nuget package linq2db.sqlserver using this package i am able to do CRUD with database first approach but i need to know how to do CRUD using code first approach. 回答1: Linq2Db has a link https://linq2db.github.io/index.html which provides more information about how to create a POCO and create a table based on it. As per the page, a simple POCO can go like this: using System; using LinqToDB.Mapping; [Table(Name = "Products")] public class

How do I tell linq2db how to translate a given expression, ie Split(char) into SQL when it does not know how to do so?

China☆狼群 提交于 2019-12-24 02:39:15
问题 I am using linq2db and while it works well enough for most CRUD operations I have encountered many expressions that it just cannot translate into SQL. It has gotten to the point where unless I know in advance exactly what kinds of expressions will be involved and have successfully invoked them before, I am worried that any benefit derived from linq2db will be outweighed by the cost of trying to find and then remove (or move away from the server side) the offending expressions. If I knew how

How to use more than one SQLite databases using LinqToDB

自作多情 提交于 2019-12-11 21:48:22
问题 I am using LinqToDB and LinqToDB.SQLite to access databases in my app. I have two separate and unique databases in my WPF app. I have two connection strings as such: <add name="AddonManager" connectionString="Data Source=AddonManager.sqlite3" providerName="SQLite" /> <add name="AddonDb" connectionString="Data Source=AddonDb.sqlite3" providerName="SQLite" /> In code I try to access the second database (AddonDb) with the following code: using (var dbContext = new DataModels.AddonDbDB()) { Guid

Executing raw SQL string using linq2db

白昼怎懂夜的黑 提交于 2019-12-10 09:38:00
问题 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<dynamic> . 回答1: You can easy implements it yourself: foreach (var rec in DataConnection.Query<dynamic>(reader => { IDictionary<string, object> eo = new ExpandoObject(); for (var index = 0; index < reader.FieldCount; index++) { eo.Add(reader.GetName(index), reader.GetValue(index)); } return eo; },

Create table with Linq to Sqlite (linq2db)

岁酱吖の 提交于 2019-12-07 04:10:12
问题 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" databases. I do my db.Insert like this: using (MyDB db = MyDB("MyConnectionName")) { Person d = new Person() { name = "mimi" }; db.Insert(d); myLabel.Content = db.Drivers.First().name; } } An empty database is opened OK. Actually a 0KB file is created for

Executing raw SQL string using linq2db

三世轮回 提交于 2019-12-05 11:57:51
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<dynamic> . You can easy implements it yourself: foreach (var rec in DataConnection.Query<dynamic>(reader => { IDictionary<string, object> eo = new ExpandoObject(); for (var index = 0; index < reader.FieldCount; index++) { eo.Add(reader.GetName(index), reader.GetValue(index)); } return eo; }, "select first 2 \"Guid\", \"DongleID\" from \"Sellings\"")) { Console.WriteLine(rec.DongleID); } First,