How do I force entity framework to use datetime instead of datetime2 to call a stored procedure?

There is an input in my stored procedure datetime

.

When edmx is built using the first database approach, we have

((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("spInsert", ... , payDateParameter);

      

And it is payDateParameter

defined as:

var payDateParameter = payDate.HasValue ?
    new ObjectParameter("PayDate", payDate.Value) :
    new ObjectParameter("PayDate", typeof(System.DateTime));

      

where payDate

- DateTime?

.

An exception:

The version of SQL Server you are using does not support the 'datetime2' data type.

I understand that there is a range limit in the data type datatime

. Therefore, for another attempt, the minimum value is added.

var payDateParameter = payDate.HasValue ?
    new ObjectParameter("PayDate", payDate.Value) :
    new ObjectParameter("PayDate", new DateTime(1753,1,1));

      

All the same exceptions.

Is there a way to force the stored procedure call to use mine payDateParameter

as a type datatime

instead datetime2

?

+3


source to share


1 answer


You need to open edmx in a text editor and change below

<Schema Namespace="CPTTModel.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2005" xmlns:store=....

      



The important thing to look out for is the "ProviderManifestToken" parameter. According to Microsoft, this setting helps the entity model not connected to the database, I think it also helps in the best way to structure the queries it makes against the target database. The difficulty is that every time you update the model data, even to move the object around in the display editor, this value is updated and stored in the database to which it is connected.

0


source







All Articles