Given this table:
CREATE TABLE [Comments]
(
[Id] [int] IDENTITY(1, 1) NOT NULL,
[Text] [nvarchar](600) NOT NULL
)
With this model class:
[Table(Name="Comments")]
public class Comment
{
[Column(AutoSync = AutoSync.OnInsert, DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
public int Id { get; set; }
[Column(DbType = "NVarChar(600) NOT NULL", CanBeNull = false)]
public string Text { get; set; }
public string ArbitraryText { get; set; }
}
Is it possible for a DataContext to fill the ArbitraryText property when using the ExecuteQuery method:
var comments = db.ExecuteQuery<Comment>("select Id, [Text], 'hello' [ArbitraryText] from Comments");
It seems that the entity mapping algorithm ignores any property not marked with ColumnAttribute, but does anyone know another way of doing this?
I'd prefer not having to do the mapping myself, but this looks like my only option.
Edit: What's annoying is that the DataContext.ExecuteQuery function will fill a "POCO" object from a query:
public class PlainOldCSharpObject
{
public int Id { get; set; }
public string Text { get; set; }
public string ArbitraryText { get; set; }
}
...
// DataContext correctly fills these objects
var pocos = db.ExecuteQuery<PlainOldCSharpObject>("select Id, [Text]...
So my current solution is to have an inner class on my LINQ-mapped object that holds the extra data my aggregate query returns. This is sub-optimal, as some properties are duplicated (e.g. Id, Text).