LINQ to SQL allow you to query and modify SQL Server database by using LINQ syntax. Entity framework is a great ORM shipped by Microsoft which allow you to query and modify RDBMS like SQL Server, Oracle, DB2 and MySQL etc. by using LINQ syntax. Today, EF is widely used by each and every .
LINQ to Entities provides Language-Integrated Query (LINQ) support that enables developers to write queries against the Entity Framework conceptual model using Visual Basic or Visual C#. Queries against the Entity Framework are represented by command tree queries, which execute against the object context.
Entity Framework Core uses Language-Integrated Query (LINQ) to query data from the database. LINQ allows you to use C# (or your . NET language of choice) to write strongly typed queries.
"As long as LINQ to SQL lives under Entity Framework, it's dead.
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
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
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 :-)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With