Problem with writing DateTime2(7)?

53 views
Skip to first unread message

NetTecture

unread,
Jan 10, 2011, 12:35:49 AM1/10/11
to Business Logic Toolkit for .NET
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?

IT

unread,
Jan 10, 2011, 1:08:12 AM1/10/11
to Business Logic Toolkit for .NET
Can I see the source of your query?

NetTecture

unread,
Jan 10, 2011, 4:02:25 AM1/10/11
to Business Logic Toolkit for .NET
No a query, an update.... The class defines the propertly as


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

The udpate is done using a

SqlQuery<T>.Insert () with the class containin the property.
> > Anyone an idea where to fix this?- Hide quoted text -
>
> - Show quoted text -

NetTecture

unread,
Mar 6, 2012, 1:45:30 AM3/6/12
to blto...@googlegroups.com
One year later, new version - same old problem.

This class:

    [TableName("Instrument", Owner = "Mkt")]
    public class MktInstrument {
 
        /// <summary>
        /// The unique Id of the instrument.
        /// </summary>
        [MapField (), PrimaryKey(), Identity()]
        public int Id { getset; }
 
        /// <summary>
        /// The Id of the symbol the instrument is attached to.
        /// </summary>
        [MapField ()]
        public int SymbolRef { getset; }
 
        /// <summary>
        /// The Timestamp of the entry.
        /// </summary>
        [MapField ()]
        public DateTime Timestamp { getset; }

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? ;)
Reply all
Reply to author
Forward
0 new messages