I’m unable to repro this issue with the code provided in this commit, which passes in both .NET Framework and .NET Core.
[Test]
public void Can_select_dynamic_results_from_custom_NamingStrategy()
{
OrmLiteConfig.BeforeExecFilter = dbCmd => Console.WriteLine(dbCmd.GetDebugString());
var hold = SqliteDialect.Provider.NamingStrategy;
SqliteDialect.Provider.NamingStrategy = new DatabaseNamingStrategy();
using (var db = OpenDbConnection())
{
db.DropAndCreateTable<Menu>();
var rows = new[] {
new Menu {
Name = "Test List",
RecId = new Guid("2F96233B-152E-4D20-BE08-5633431A9EBC")
}
};
db.InsertAll(rows);
var q = db.From<Menu>().Select(x => new { x.Id, x.RecId, x.Name });
var results = db.Select<(int id, Guid recId, string name)>(q);
var expected = rows[0];
Assert.That(results[0].id, Is.EqualTo(1));
Assert.That(results[0].recId, Is.EqualTo(expected.RecId));
Assert.That(results[0].name, Is.EqualTo(expected.Name));
}
SqliteDialect.Provider.NamingStrategy = hold;
}
Which generates the following SQL:
SQL: CREATE TABLE "menu"
(
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
"parent_id" INTEGER NULL,
"name" VARCHAR(100) NOT NULL,
"form" VARCHAR(100) NULL,
"icon" VARCHAR(50) NULL,
"style" VARCHAR(1000) NULL,
"user_id" INTEGER NULL,
"is_deleted" INTEGER NOT NULL DEFAULT (0),
"is_active" INTEGER NOT NULL DEFAULT (1),
"position" INTEGER NULL,
"rec_id" CHAR(36) NOT NULL,
CONSTRAINT "FK_menu_menu_ParentId" FOREIGN KEY ("parent_id") REFERENCES "menu" ("id")
);
SQL: INSERT INTO "menu" ("parent_id","name","form","icon","style","user_id","is_deleted","is_active","position","rec_id") VALUES (@ParentId,@Name,@Form,@Icon,@Style,@UserId,@IsDeleted,@IsActive,@Position,@RecId)
PARAMS: @ParentId=, @Name=Test List, @Form=, @Icon=, @Style=, @UserId=, @IsDeleted=0, @IsActive=1, @Position=, @RecId=2f96233b-152e-4d20-be08-5633431a9ebc
SQL: SELECT "id", "rec_id", "name"
FROM "menu"
The one change that was needed for OrmLite was making UserId
public
and removing the ForeignKey reference since no User class was provided but as it’s not apart of the query it wont have any effect on the test.
If you haven’t already please upgrade to the latest version of OrmLite, if it’s still an issue please upload a stand-alone repro on GitHub I can run locally to repro the issue.