igor-tkachev/bltoolkit — Issue #79: Impossible to use high precision DateTime types...
Author: NetTecture
Created: 2012-03-06 06:46:59+00:00
State: open

One year later, new version - same old problem ;) This time no workaround.

This class:

[TableName("Instrument", Owner = "Mkt")]
public class MktInstrument {

///

/// The unique Id of the instrument.
///

[MapField (), PrimaryKey(), Identity()]
public int Id { get; set; }

///

/// The Id of the symbol the instrument is attached to.
///

[MapField ()]
public int SymbolRef { get; set; }

///

/// The Timestamp of the entry.
///

[MapField ()]
public DateTime Timestamp { get; set; }

with this query:

using (DataManager manager = new DataManager(_DatabaseConfig)) {
manager.GetRepository().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

I need full precision - I use the last digits of the DateTime to "index it" (i.e. provide an order for elements with the same timestamp). This is severely ingrained into the whole codebase.

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? ;)

On Monday, January 10, 2011 6:35:49 AM UTC+1, NetTecture wrote:
Hello,

I am trying to write out tick consistent DateTime2(7) values into SQL
Server. I pretty much plan to use th last digits below milliseconds to
order the data I get (in actuall 25ms intervals).

I write, for example:

+ TimeOfDay {05:00:07.4250141} System.TimeSpan

And in the database I then find:

2010-12-14 05:00:07.4270000

This clarly has been rounded ;) Which sadly is not good for me.

Anyone an idea where to fix this?

On Monday, January 10, 2011 6:35:49 AM UTC+1, NetTecture wrote:
Hello,

I am trying to write out tick consistent DateTime2(7) values into SQL
Server. I pretty much plan to use th last digits below milliseconds to
order the data I get (in actuall 25ms intervals).

I write, for example:

+ TimeOfDay {05:00:07.4250141} System.TimeSpan

And in the database I then find:

2010-12-14 05:00:07.4270000

This clarly has been rounded ;) Which sadly is not good for me.

Anyone an idea where to fix this?

On Monday, January 10, 2011 6:35:49 AM UTC+1, NetTecture wrote:
Hello,

I am trying to write out tick consistent DateTime2(7) values into SQL
Server. I pretty much plan to use th last digits below milliseconds to
order the data I get (in actuall 25ms intervals).

I write, for example:

+ TimeOfDay {05:00:07.4250141} System.TimeSpan

And in the database I then find:

2010-12-14 05:00:07.4270000

This clarly has been rounded ;) Which sadly is not good for me.

Anyone an idea where to fix this?