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

Commit 283a775

Browse files
committed
Add create table ignore fields test
1 parent dad8a77 commit 283a775

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

tests/ServiceStack.OrmLite.Tests/OrmLiteCreateTableTests.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,5 +441,54 @@ public void Does_CreateTableIfNotExists()
441441
Assert.That(rows[0].Id, Is.EqualTo(1));
442442
}
443443
}
444+
445+
public class TableWithIgnoredFields
446+
{
447+
public int Id { get; set; }
448+
449+
public string FirstName { get; set; }
450+
451+
public string LastName { get; set; }
452+
453+
public string DisplayName
454+
{
455+
get { return FirstName + " " + LastName; }
456+
}
457+
458+
[DataAnnotations.Ignore]
459+
public int IsIgnored { get; set; }
460+
461+
public Nested Nested { get; set; }
462+
}
463+
464+
public class Nested
465+
{
466+
public string Name { get { return "Foo"; } }
467+
}
468+
469+
[Test]
470+
public void Does_not_create_table_with_ignored_field()
471+
{
472+
using (var db = OpenDbConnection())
473+
{
474+
db.DropAndCreateTable<TableWithIgnoredFields>();
475+
476+
Assert.That(db.GetLastSql(), Is.StringContaining("DisplayName"));
477+
Assert.That(db.GetLastSql(), Is.Not.StringContaining("IsIgnored"));
478+
479+
db.Insert(new TableWithIgnoredFields
480+
{
481+
Id = 1,
482+
FirstName = "Foo",
483+
LastName = "Bar",
484+
IsIgnored = 10,
485+
});
486+
487+
var row = db.Select<TableWithIgnoredFields>()[0];
488+
489+
Assert.That(row.DisplayName, Is.EqualTo("Foo Bar"));
490+
Assert.That(row.IsIgnored, Is.EqualTo(0));
491+
}
492+
}
444493
}
445494
}

0 commit comments

Comments
 (0)