Entity Framework. Delete all rows in table

For those that are googling this and ended up here like me, this is how you currently do it in EF5 and EF6: context.Database.ExecuteSqlCommand(“TRUNCATE TABLE [TableName]”); Assuming context is a System.Data.Entity.DbContext Edit: Currently in net6.0 (dotnet 6 core) you can do the following: context.Database.ExecuteSqlRaw(“TRUNCATE TABLE [TableName]”); Or use the Async overload: await context.Database.ExecuteSqlRawAsync(“TRUNCATE TABLE [TableName]”); … Read more

Extract date (yyyy/mm/dd) from a timestamp in PostgreSQL

You can cast your timestamp to a date by suffixing it with ::date. Here, in psql, is a timestamp: # select ‘2010-01-01 12:00:00′::timestamp; timestamp ——————— 2010-01-01 12:00:00 Now we’ll cast it to a date: wconrad=# select ‘2010-01-01 12:00:00’::timestamp::date; date ———— 2010-01-01 On the other hand you can use date_trunc function. The difference between them is … Read more

Validation failed for one or more entities while saving changes to SQL Server Database using Entity Framework

You can extract all the information from the DbEntityValidationException with the following code (you need to add the namespaces: System.Data.Entity.Validation and System.Diagnostics to your using list): catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation(“Property: {0} Error: {1}”, validationError.PropertyName, validationError.ErrorMessage); } } }

INSERT with SELECT

Yes, absolutely, but check your syntax. INSERT INTO courses (name, location, gid) SELECT name, location, 1 FROM courses WHERE cid = 2 You can put a constant of the same type as gid in its place, not just 1, of course. And, I just made up the cid value.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)