One year later, new version - same old problem.
[TableName("Instrument", Owner = "Mkt")]
public class MktInstrument {
/// <summary>
/// The unique Id of the instrument.
/// </summary>
[MapField (), PrimaryKey(), Identity()]
public int Id { get; set; }
/// <summary>
/// The Id of the symbol the instrument is attached to.
/// </summary>
[MapField ()]
public int SymbolRef { get; set; }
/// <summary>
/// The Timestamp of the entry.
/// </summary>
[MapField ()]
public DateTime Timestamp { get; set; }
with this query:
using (DataManager manager = new DataManager(_DatabaseConfig)) {
manager.GetRepository<MktInstrument>().Insert (
() => new MktInstrument() {
SymbolRef = mktSymbol.Id,
Timestamp = timestamp,
}
);
(non relevant fields taken out)
rounds.
DataManager just wrapps a DbManager - GetRepository maps to the GetTable method.
The culprit is that the parameter for timestmap is DateTime.
The generated query is:
INSERT INTO [Mkt].[Instrument]
(
[SymbolRef],
[Timestamp],
)
VALUES
(
@Id,
@timestamp1,
)
The Timestamp field in the database is DateTime2(7).
The parameter used (@timestamp1) is: DbType: System.Data.DbType.DateTime
This seems to be the culprit. Is there any way to override that type? I tried adding a BLToolkit.DataAccess.DbTypeAttribute but it is ignored (parameter value still DateTime). The DateTime value in the parameter is correct, so it seems totally to be the bad data type.
Any help please? ;)