I am testing an application on server with SQL Server 2005 and I am getting the following error (the application runs fine with SQL Server 2008 R2 and 2012 versions).
There is no store type corresponding to the conceptual side type 'Edm.Time(Nullable=True,DefaultValue=,Precision=)' of PrimitiveType 'Time'.`
The code inside the Controller that might responsible for the error is ('might' because when this code is invoked the database does not exist yet and Entity Framework is supposed to generate the database)
var tempRegistrations = db.Registrations.Where(t => t.DateExpires < DateTime.Now).ToList();
The code in my Model responsible for the entry in question is
public class Registrations
{
public int RegistrationsId { get; set; }
// ...
public DateTime? DateExpires { get; set; }
}
Both, SQL Server 2008 R2 and 2012 versions had datetime data type (nullable as well) in the generated table. I am quite sure SQL Server 2005 has datetime datatype. So what is wrong here?
Thanks.
Seems SQL 2005 doesn't support the Time datatype, which is what it's trying to map it to. Perhaps change it on the Edm side to use
datetime?
http://msdn.microsoft.com/en-us/library/bb896344.aspx
PrimitiveType 'Time'
Are you sure it's not trying to create a datatype of time? 2005 does not have this type.
I'm not sure if this is what you're using, but it looks like there is a difference between time and datetime.
http://msdn.microsoft.com/en-us/library/ee382832.aspx
Related
I have a simple stored procedure to return a datetime. e.g:
create procedure sp_get_date (#db_date datetime output)as begin select #db_date ='2017-04-26 13:20:32.313' end
And using SQLNCLI11 native client to work with the datatbase inside the PowerBuilder application.
DECLARE get_date_proc PROCEDURE for dbo.sp_get_date #db_date = :dt_today output using sqlca;
EXECUTE get_date_proc;
FETCH get_date_proc INTO :dt_today;
t_now = time(dt_today)
The expected result for t_now is "13:20:32.313000"
When use SQL sever 2014, the t_now value is correct with 13:20:32.313000
But with SQL server 2016, the value is 13:20:3133333
Is that the problem with native client library to work with SQL server 2016? Is the stored procudure return a datatime2 value?
Thanks a lot.
It looks like you are running into this sql server bug (https://connect.microsoft.com/SQLServer/Feedback/Details/2805477). So it seems the best approach may be to convert the datatype of your parameter to datetime2. Alternatively, it might help to implement the procedure as a RPC in your PB app; I can't really say if that does anything since I'm still using ss 2012.
I have read several post around the problem but found not solution to the issue I'm facing with.
My entity model contains several date properties whose values I need to be set at SQL server level. Here's an example:
[Column(IsDbGenerated = true)]
public DateTime DateCreated { get; set; }
DateCreated is a 'date' type on SQL Server, and its default value is GETDATE().
[DateCreated] DATE DEFAULT (getdate()) NOT NULL,
As a matter of fact saving a new record (without passing any DateCreated value) results in '1/1/0001' (i.e. null datetime) value being inserted.
It looks like Linq overrides default server GETDATE() value, forcing a 'null' value to be written.
You must use DatabaseGenerationOption.Identity.
Here are two links that explain further:
Entity Framework Code First Data Annotations
How do I tell Entity Framework to allow SQL Server to provide a defined default value for a field?
Using SQLCOmmand to insert row in database. SQL Command is using parameters.
To get the query while debugging at Immediate window I use
?_cmd.CommandText
Result:
"UPDATE TABLE SET Smth=#Smth, Smth2=#Smth2 "
How to get complete query where I instead of #Smth and #Smth2 will have values read from parameters?
If you have access to SSMS, then you could use SQL Server Profiler to trace the actual SQL commands being issued by your VB.NET application when you run it.
Note that running SQL Server Profiler has a performance overhead on the database server, so would strongly advise against running it on a Production server or a server where you would affect others.
Some links on how to get started with SQL Server Profiler...
https://www.mssqltips.com/sqlservertutorial/272/profiler-and-server-side-traces/
http://blog.sqlauthority.com/2009/08/03/sql-server-introduction-sql-server-2008-profiler-complete/
You can write a helper method:
public static class Helper
{
public static string ToString(this DbParameterCollection params, string query)
{
return params.Cast<DbParameter>().Aggregate(query, (c, p) => c.Replace(p.ParameterName, p.Value.ToString()));
}
}
try :
INSERT INTO TABLE SET Smth=#Smth, Smth2=#Smth2 WHERE <somecondition>
Select #Smth,#Smth2
Unique constraint is implemented by unique index in Sql Server 2005/2008 for the following:
#Column(name = "SOME_ID", unique = true)
public String getSomeId() {
return someId;
}
Sql Server generates UQ__USERS__135061FE4316F928, is it possible to specify a user defined name from hibernate?
There is no name = XYZ for #Column.
#org.hibernate.annotations.Index does have a name however, I couldn't find a way to specify a unique index in that case.
I'm using JPA/Hibernate 4.1.9, SQL Server 2008
Its a known issue and as discussed in the comments of this jira. HB-1245 the work around would be to export the schema and tweak the DDL to add the constraint names.
When pulling dates from a view using JPA and EclipseLink I'm getting dates two days before the date in the SQL data. (ie 1965-01-01 becomes 1964-12-30 and 1998-12-31 becomes 1998-12-29)
I am mapping date fields in SQL Server 2008 R2 with the following annotations:
#Entity
#Table(name = "vw_Record")
#XmlRootElement
public class VwRecord implements Serializable {
#Column(name = "dateStart")
#Temporal(TemporalType.DATE)
private Date dateStart;
#Column(name = "dateEnd")
#Temporal(TemporalType.DATE)
private Date dateEnd;
The columns in SQL Server are defined as:
[dateStart] [date] NULL,
[dateEnd] [date] NULL
Any ideas why I am getting a consistent two day difference?
EclipseLink does not do any conversion, it is most likely occurring in JDBC.
You can trying executing a native SQL query through JPA and see what data it returns. Also try selecting the data through raw JDBC.