Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding DateTime2 parameter #188

Open
maxoizs opened this issue Nov 6, 2014 · 9 comments
Open

Adding DateTime2 parameter #188

maxoizs opened this issue Nov 6, 2014 · 9 comments

Comments

@maxoizs
Copy link

maxoizs commented Nov 6, 2014

Adding full DateTime with milliseconds in petepoco AddParam will be treated as DateTime which will loss the milliseconds part, and if I amend the if else case with

else if (item.GetType().Name == "DateTime")
        {
          p.DbType = DbType.DateTime2;
          p.Value = item;
        }

will treat all DateTime parameters as DateTime2 which ok in my case as I'm using DateTime2 everywhere but it'll invalid the where clause for DateTime parameter if it's against DateTime only column.

I wonder if it possible to determine the column type for the parameter ?

@pleb pleb added the question label Dec 4, 2015
@pleb
Copy link
Member

pleb commented Dec 13, 2015

Seems like something that PP should allow to be configured

@0ndrej
Copy link

0ndrej commented Aug 10, 2016

I just bumped into this problem now. Recommended type for MSSQL date is datetime2, while PetaPoco is mapping everything to datetime. If I create POCO class with .NET DateTime property, exception is thrown when trying to Insert, because of SQL datetime overflow even though it is defined as datetime2 in database.

@tkouba
Copy link
Contributor

tkouba commented Apr 13, 2018

One possible solution is adding function to interface IProvider DbType MapParameterValue(object value, PropertyInfo pi); and use it in Database.AddParam. What is your opinion?

@maxoizs
Copy link
Author

maxoizs commented Apr 18, 2018

Sorry guys, It's been so long and I've actually forgot about it totally. therefore I'm sure I won't be of much help.

@pleb
Copy link
Member

pleb commented Apr 18, 2018

No worries mate. I should have some free time starting mid-year. Tickets, list this one, are on my list ;)

@roggmaeh
Copy link

I just have the same problem. Is a fix like AnsiString workaround (varchar/nvarchar) possible?

@roggmaeh
Copy link

roggmaeh commented Dec 27, 2021

AnsiString and DateTime2 fix
roggmaeh@7ef1a8f

my table model
[Column("DATECHANGE", IsDateTime2 = true)]
public DateTime? DATECHANGE {get;set;)

[Column("NAME", IsAnsi = true)]
public string NAME {get;set;}

@asherber
Copy link
Collaborator

@roggmaeh Can you please open a pull request so we can review and comment?

@asherber
Copy link
Collaborator

Please see my comments in the PR. I'm not sure that this work is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants