+4  A: 

To show the created SQL commands for debugging in EF

using System.Data.Objects;
...
var sqlQuery = query as ObjectQuery<T>;
var sqlTrace = sqlQuery.ToTraceString();

AFAIK there are no commands to create DB's or do any sort of DDL work. This is design limitation of the "Entity SQL" language

The EDMX design surface will map your current database schema, not the other way around

TFD
+2  A: 

To execute a SQL command against the database in EF

using System.Data.EntityClient;
...
EntityConnection conn = new EntityConnection(myContext.Connection.ConnectionString);
conn.Open();
EntityCommand cmd = conn.CreateCommand();
cmd.CommandText = @"Select t.MyValue From MyEntities.MyTable As t";
var result = cmd.ExecuteReader(System.Data.CommandBehavior.SequentialAccess);
result.Read();
var myValue = result.GetValue(0);
...
conn.Close();

The command text is in Entity SQL which is not 100% the same as T-SQL

TFD
I would love to use the same Connection as the context uses. I tried EntityConnection conn = new EntityConnection(myContext.MetadataWorkspace, myContext.Connection), but this trows a funky InvalidoperationException (something like System.Data.SqlClient is not the same as the one in connectionstring)
Sam
Dang, to my dismay I just noticed, EntitySQL (eSQL) does not support insert, update, delete commands, and bulk update was the whole reason for needing it. Pity.
Sam
+2  A: 

To get the new identity value from an insert in EF

Create Table dbo.MyItem (
    Id int indentity(1, 1) Primary Key,
    Value varchar(100)
)

var newItem = new MyItem() { Value = "Hello" };
context.AddToMyItem(newItem);
context.SaveChanges(true);
var theNewIdentityValue = newItem.Id;

The EF folks just made this to easy, nice work :-)

TFD
This needs identity(1,1) to work? It does not work with Guid's, it seems to me?
Sam
+1  A: 

In L2S you can just use stored procedures like function calls. In EF the SP has to return an entity. This can cause problems if your SP only returns a subset of a full entity

Jacob Adams