locked
Linq to Entities vs TSQL RRS feed

  • Question

  • Hi,

    I am used to TSQL, now start to learn linq to entities, I feel very confused. Are there any articles that tell me what tsql does but linq to entities cannot do or very difficult to do?

    Thanks.

    Friday, January 13, 2012 4:33 AM

Answers

  • On 1/13/2012 5:52 AM, peter 9 wrote:
    > Hi,
    >
    > Thank u for your help. For me, I don't think linq to entities will be
    > easier in most of time. I love tsql and also most of my queries are
    > complicated. But linq is there, I don't want to abandon it, instead, I
    > like to master it. What I want to know is that what kinds of query in
    > tsql cannot be achived in linq to entities or are very hard to achieved?
    > So I can avoid to wast a lot of time on linq to entities.
    >
     I don't think anyone can tell you that. You are going to have to run
    into the situation and come to the conclusion that you can't use Linq
    for this.
     
    For querying against the EF Model, you can also use Entity SQL with a
    datareader and do the same things you can do with T-SQL and a
    datareader. You can populate the entity on the model and return an
    entity, populate collections within an entity, and return collections of
    entities while using the ESQL DBdatareader.
     
     
    inner joins, outer joins, cast etc etc.  As far as querying, you can do
    with E-SQL like you can with T-SQL, populate the entities on the model
    with a dbreader, get multiple returned results the whole 9 yards.
     
     
    You can also use ESQL this way too.
     
     
    As far as you finding some kind of information on what T-SQL can do that
    Linq cannot do, good luck on your search.
     
     
    • Marked as answer by peter 9 Sunday, January 15, 2012 9:59 PM
    Friday, January 13, 2012 3:06 PM

All replies

  • On 1/12/2012 11:33 PM, peter 9 wrote:
    > Hi,
    >
    > I am used to TSQL, now start to learn linq to entities, I feel very
    > confused. Are there any articles that tell me what tsql does but linq to
    > entities cannot do or very difficult to do?
    >
    You do know that linq has a T-SQL engine that generates T-SQL to be
    submitted to the database for execution.
     
    Of course you can have a situation that arises that you may have to go
    to the backdoor to T-SQL over linq-2-entities. You'll have to discover
    those situations when you may need to go to the backdoor.
     
     
    You can also call a sproc in the ORM without using the backdoor.
     
     
    The thing with Linq is it may not create optimal T-SQL, and you have to
    use something like a SQL Profiler to see what the T-SQL generated is doing.
     
    You'll use the functionality of Linq with a Linq method that cannot do
    it against a database table, but it can be done with Linq-2-Objects,
    because it is not going against a database table to materialize objects.
    You'll see that error message from time to time. Again, you'll have to
    discover them.
     
    As far as some kind of list explaining what you want, I have never seen one.
     
    The main purpose of Linq is to be able to query a query-able source and
    return the result as an encapsulated object or objects in a tubular form.
     
    You can practice with this.
     
     
    Friday, January 13, 2012 5:55 AM
  • Hi,

    Thank u for your help. For me, I don't think linq to entities will be easier in most of time. I love tsql and also most of my queries are complicated. But linq is there, I don't want to abandon it, instead, I like to master it. What I want to know is that what kinds of query in tsql cannot be achived in linq to entities or are very hard to achieved? So I can avoid to wast a lot of time on linq to entities.

    Thanks again. 

    Friday, January 13, 2012 10:52 AM
  • On 1/13/2012 5:52 AM, peter 9 wrote:
    > Hi,
    >
    > Thank u for your help. For me, I don't think linq to entities will be
    > easier in most of time. I love tsql and also most of my queries are
    > complicated. But linq is there, I don't want to abandon it, instead, I
    > like to master it. What I want to know is that what kinds of query in
    > tsql cannot be achived in linq to entities or are very hard to achieved?
    > So I can avoid to wast a lot of time on linq to entities.
    >
     I don't think anyone can tell you that. You are going to have to run
    into the situation and come to the conclusion that you can't use Linq
    for this.
     
    For querying against the EF Model, you can also use Entity SQL with a
    datareader and do the same things you can do with T-SQL and a
    datareader. You can populate the entity on the model and return an
    entity, populate collections within an entity, and return collections of
    entities while using the ESQL DBdatareader.
     
     
    inner joins, outer joins, cast etc etc.  As far as querying, you can do
    with E-SQL like you can with T-SQL, populate the entities on the model
    with a dbreader, get multiple returned results the whole 9 yards.
     
     
    You can also use ESQL this way too.
     
     
    As far as you finding some kind of information on what T-SQL can do that
    Linq cannot do, good luck on your search.
     
     
    • Marked as answer by peter 9 Sunday, January 15, 2012 9:59 PM
    Friday, January 13, 2012 3:06 PM