You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `options` parameter let you use a lambda expression to customize the way entities are inserted/updated.
75
65
76
66
```csharp
77
-
bulk.ColumnPrimaryKeyExpression=c=>c.Code;
67
+
bulk.AutoMapKeyExpression=c=>c.Code;
78
68
bulk.BulkMerge(customers);
79
69
```
80
70
[Try it (Entity)](https://dotnetfiddle.net/5wMQ6X)
81
71
72
+
```csharp
73
+
bulk.AutoMapKeyName="Code";
74
+
bulk.BulkMerge(customers);
75
+
```
82
76
[Try it (DataTable)](https://dotnetfiddle.net/JJIPCB)
83
77
84
78
## Real Life Scenarios
@@ -111,34 +105,47 @@ bulk.BulkMerge(customers);
111
105
```
112
106
[Try it (Entity)](https://dotnetfiddle.net/W4TJkK)
113
107
108
+
```csharp
109
+
varcolumnMapping=newColumnMapping("CreatedDate");
110
+
111
+
columnMapping.IgnoreOnMergeUpdate=true;
112
+
113
+
bulk.ColumnMappings.Add("CustomerID", true);
114
+
bulk.ColumnMappings.Add("UpdatedDate");
115
+
bulk.ColumnMappings.Add("Name");
116
+
bulk.ColumnMappings.Add(columnMapping);
117
+
bulk.BulkMerge(dtCustomers);
118
+
```
119
+
[Try it (DataTable)](https://dotnetfiddle.net/TIfeSG)
120
+
114
121
### Merge with custom key
115
122
You want to merge entities, but you don't have the primary key. The `ColumnPrimaryKeyExpression` let you use as a key any property or combination of properties.
116
123
117
124
```csharp
118
-
bulk.ColumnPrimaryKeyExpression=c=>c.Code
119
-
bulk.BulkMerge(customers);
125
+
bulk.AutoMapKeyExpression=c=>c.Code;
126
+
bulk.BulkMerge(customers);
120
127
```
121
128
[Try it (Entity)](https://dotnetfiddle.net/Xlcdxq)
122
129
130
+
```csharp
131
+
bulk.AutoMapKeyName="Code";
132
+
bulk.BulkMerge(customers);
133
+
```
123
134
[Try it (DataTable)](https://dotnetfiddle.net/9KOxdW)
124
135
136
+
125
137
### Merge with related child entities
126
138
You want to merge entities but also merge related child entities.
0 commit comments