@@ -44,9 +44,17 @@ You can also register additional options (like interceptors) for LinqToDB during
44
44
``` cs
45
45
var optionsBuilder = new DbContextOptionsBuilder <MyDbContext >();
46
46
optionsBuilder .UseSqlite ();
47
- optionsBuilder .UseLinqToDb (builder =>
47
+ optionsBuilder .UseLinqToDB (builder =>
48
48
{
49
+ // add custom command interceptor
49
50
builder .AddInterceptor (new MyCommandInterceptor ());
51
+ // add additional mappings
52
+ builder .AddMappingSchema (myCustomMappings );
53
+ // configure SQL Server dialect explicitly
54
+ // builder.AddCustomOptions(o => o.UseSqlServer(SqlServerVersion.v2022));
55
+ // due to bug in linq2db 5.0.0, use overload with connection string
56
+ // will be fixed in next linq2db release
57
+ builder .AddCustomOptions (o => o .UseSqlServer (" unused" , SqlServerVersion .v2022 ));
50
58
});
51
59
```
52
60
@@ -58,10 +66,10 @@ ctx.BulkCopy(new BulkCopyOptions {...}, items);
58
66
59
67
// query for retrieving products that do not have duplicates by Name
60
68
var query =
61
- from p in ctx .Products
62
- from op in ctx .Products .LeftJoin (op => op .ProductID != p .ProductID && op .Name == p .Name )
63
- where Sql .ToNullable (op .ProductID ) == null
64
- select p ;
69
+ from p in ctx .Products
70
+ from op in ctx .Products .LeftJoin (op => op .ProductID != p .ProductID && op .Name == p .Name )
71
+ where Sql .ToNullable (op .ProductID ) == null
72
+ select p ;
65
73
66
74
// insert these records into the same or another table
67
75
query .Insert (ctx .Products .ToLinqToDBTable (), s => new Product { Name = s .Name .. . });
@@ -90,13 +98,13 @@ It is not required to work directly with `LINQ To DB` `DataConnection` class but
90
98
91
99
``` cs
92
100
// uing DbContext
93
- using (var dc = ctx .CreateLinqToDbConnection ())
101
+ using (var dc = ctx .CreateLinqToDBConnection ())
94
102
{
95
103
// linq queries using linq2db extensions
96
104
}
97
105
98
106
// using DbContextOptions
99
- using (var dc = options .CreateLinqToDbConnection ())
107
+ using (var dc = options .CreateLinqToDBConnection ())
100
108
{
101
109
// linq queries using linq2db extensions
102
110
}
@@ -110,35 +118,35 @@ Async methods have the same name but with `LinqToDB` suffix. E.g. `ToListAsyncLi
110
118
``` cs
111
119
using (var ctx = CreateAdventureWorksContext ())
112
120
{
113
- var productsWithModelCount =
114
- from p in ctx .Products
115
- select new
116
- {
117
- // Window Function
118
- Count = Sql .Ext .Count ().Over ().PartitionBy (p .ProductModelID ).ToValue (),
119
- Product = p
120
- };
121
-
122
- var neededRecords =
123
- from p in productsWithModelCount
124
- where p .Count .Between (2 , 4 ) // LINQ To DB extension
125
- select new
126
- {
127
- p .Product .Name ,
128
- p .Product .Color ,
129
- p .Product .Size ,
130
- // retrieving value from column dynamically
131
- PhotoFileName = Sql .Property <string >(p .Product , " ThumbnailPhotoFileName" )
132
- };
133
-
134
- // ensure we have replaced EF context
135
- var items1 = neededRecords .ToLinqToDB ().ToArray ();
136
-
137
- // async version
138
- var items2 = await neededRecords .ToLinqToDB ().ToArrayAsync ();
139
-
140
- // and simple bonus - how to generate SQL
141
- var sql = neededRecords .ToLinqToDB ().ToString ();
121
+ var productsWithModelCount =
122
+ from p in ctx .Products
123
+ select new
124
+ {
125
+ // Window Function
126
+ Count = Sql .Ext .Count ().Over ().PartitionBy (p .ProductModelID ).ToValue (),
127
+ Product = p
128
+ };
129
+
130
+ var neededRecords =
131
+ from p in productsWithModelCount
132
+ where p .Count .Between (2 , 4 ) // LINQ To DB extension
133
+ select new
134
+ {
135
+ p .Product .Name ,
136
+ p .Product .Color ,
137
+ p .Product .Size ,
138
+ // retrieving value from column dynamically
139
+ PhotoFileName = Sql .Property <string >(p .Product , " ThumbnailPhotoFileName" )
140
+ };
141
+
142
+ // ensure we have replaced EF context
143
+ var items1 = neededRecords .ToLinqToDB ().ToArray ();
144
+
145
+ // async version
146
+ var items2 = await neededRecords .ToLinqToDB ().ToArrayAsync ();
147
+
148
+ // and simple bonus - how to generate SQL
149
+ var sql = neededRecords .ToLinqToDB ().ToString ();
142
150
}
143
151
```
144
152
@@ -165,9 +173,11 @@ Below is a list of providers, that should work right now:
165
173
- Oracle
166
174
- SQL Server CE
167
175
168
- # Know limitations
176
+ # Known limitations
169
177
- No Lazy loading
170
178
- No way to work with in-memory database
179
+ - No TPT (table per type) support
180
+ - No many-to-many support
171
181
172
182
# Help! It doesn't work!
173
183
0 commit comments