Saturday, September 6, 2014

EF5: Cannot attach the file ‘{0}' as database '{1}'

Go to View -> SQL Server Object Explorer and delete the database from the (localdb)\v11.0 subnode!

Delete the database

The model backing the context has changed since the database was created

Database.SetInitializer<YourDbContext>(null);
or


Database.SetInitializer(new DropCreateDatabaseIfModelChanges<YourDbContext>());
for later versions

Wednesday, August 27, 2014

Computed Columns and CASE SQL Server

CASE
       WHEN shipdate is NULL AND orderdate < DATEADD( dd, -7, GETDATE()) THEN 3
       WHEN shipdate is NOT NULL THEN 2
       ELSE 1
END

Wednesday, August 20, 2014

How to convert type 'byte[]' to 'System.Data.Linq.Binary'

System.Data.Linq.Binary has a constructor taking 1 argument of byte[]:

var byt = new System.Data.Linq.Binary(bytes);

Friday, August 15, 2014

Get datakey value inside listview itemcommand

ListViewItem lvi = e.Item;
int id = Convert.ToInt32(ListView1.DataKeys[lvi.DataItemIndex].Value);