Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 2f657c6

Browse files
committed
Add example of temporarily overriding IsComputed property
1 parent c1f1a50 commit 2f657c6

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/ServiceStack.OrmLite.Tests/OrmLiteInsertTests.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,46 @@ public void Can_InsertOnly_selected_fields_using_AssignmentExpression()
271271
Assert.That(row.LastName, Is.Null);
272272
}
273273
}
274+
275+
[Test]
276+
public void Can_insert_record_with_Computed_column()
277+
{
278+
using (var db = OpenDbConnection())
279+
{
280+
db.DropAndCreateTable<Market>();
281+
var market = new Market
282+
{
283+
Available = 10,
284+
AvailableTotal = 0,
285+
AvailableSalesEvent = 2,
286+
MinCustomerBuy = 10
287+
};
288+
289+
var fieldDef = typeof(Market).GetModelMetadata()
290+
.GetFieldDefinition<Market>(x => x.AvailableTotal);
291+
292+
fieldDef.IsComputed = false;
293+
294+
db.Insert(market);
295+
296+
fieldDef.IsComputed = true;
297+
}
298+
}
299+
}
300+
301+
public class Market
302+
{
303+
[AutoIncrement]
304+
public int Id { get; set; }
305+
[Required]
306+
public int Available { get; set; }
307+
[Required]
308+
public int AvailableSalesEvent { get; set; }
309+
[Compute]
310+
[Required]
311+
public int AvailableTotal { get; set; }
312+
[Required]
313+
public int? MinCustomerBuy { get; set; }
274314
}
275315

276316
public class UserAuth

0 commit comments

Comments
 (0)