Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

How to execute two EF linq query with one db round trip

$
0
0

when we work with ado.net then we can pass multiple sql separated by comma. here is one example.

SqlConnection connection = new SqlConnection();
SqlCommand command = new SqlCommand();
connection.ConnectionString = connectionString; // put your connection string
command.CommandText = @"
     update table
     set somecol = somevalue;
     insert into someTable values(1,'test');";
command.CommandType = CommandType.Text;
command.Connection = connection;

try
{
    connection.Open();
}
finally
{
    command.Dispose();
    connection.Dispose();
}

i like to know how could i construct EF linq based query which will fetch data from multiple table but there is no relation between two table. so we can not perform join.

so show me a example where EF will fetch data from student and product table without any join with one db round trip. is it possible which was possible by ado.net as per my above example.

 var query = from data in context.Student

                orderby data.name

                select data;

 var query = from data in context.Product

                orderby data.name

                select data;

when two above query will run then two database round trip will occur or one ?

i need to fetch data from two table called student and product with one db round trip just like my above EF linq query.

if possible then discuss with sample code. thanks


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>