Using LINQ and ADO.NET Entity Data Model - asp.net-mvc

Is it possible to use LINQ and ADO.NET Entity Data Model together in a project? I have a project built on ADO.NET Entity Data Model from a previous user and has .edmx file, but I am used to hard coding everything, opening connections via ADO.NET.
Is there problems using both together in an MVC project?

LINQ(Language Integrated Query) is TSQL in C# (yes we can query xml, lamda expression etc its lot more but mostly used for TSQL...) you can write LINQ queries against LINQ to SQL (.dbml) OR Entity Framework (.edmx) by creating the Context of each there is a bit of diff in calling methods like in EF Object.AddToObject(o) and in LINQ to SQL Object.InsertOnSubmit(o) and .Savechanges()/Submitchanges()
LINQ to SQL supports only MS SQL server but EF can support other databases as well i.e. MY SQL etc
and if you are using any of these in your project you can still use old Ado.net anywhere in your project by providing proper info to methods or call stored procedures by passing parameters after opening connection like we did in old days......

Linq is simply a way of writing your sql in C#. Well it's lot more than that really. But in this context whereever you would put some sql, you use linq intead so it's agnostic as far as EF is concerned. Or any other framework for that matter.
The real bonus is with a bit of thought you can use something other than a sql database for your persistence.

There are 2 sorts of Linq
Linq To Objects and Linq to SQL
Linq to SQL wont work on your ADO Model as that requires a Direct link to the SQL
but Linq to objects will work on the ADO models objects just as easily as any other
in real terms all this means is that instead of managing the construction for the query's in the DB Linq will let ADO handle it, you wouldn't see any difference

Related

How can I handle different server and different to connect Asp.net Web API using linq and lambda

Previously, My older API version is connecting different server and database from code side. I called sql query, views and store procedures directly asking from client which server and database need to connect and then return respective JSON results to clients.
For now, I would like to convert Linq and Lambda expression and also I would like to use edmx and entity framework .
Please kindly response me if there any suggestion about this.
Because you already have a database use entity framework database first that will generate your models automatically and will create a Super Class called Dbcontext where you will find all the database tables and later on you will use LINQ to get data from Dbcontext.
useful link Ef databasefirst.
search for entity framework database first this will help you.

ADO.net data access srtategy in MVC application

This is not really related to Programming But I do need a answer for that if anyone know.
What are the ADO.net Data access strategies for MVC application. choices are
1-DataAdapter
2-Datareader
3-EntityFramework
5-LinqtoSQL
I know that there is a DataReader that provides stream of data from the data source and DataAdapter provides the bridge between the DataSet object and the data source but not sure if that is call Data access strategy, I know Linq to SQL and EntityFramework are the Strategies. Please help
Data Access Technology
SQL data access options available in .NET framework are; Entity Framework, LINQ to SQL and SQL client.
Solution
SQL client
SQL client requires writing custom queries or stored procedures for each data access operations and extra code work to convert them into .NET objects. This technique will be beneficial when complex and dynamic queries are used very often. SQL client provides the best performance of these three technologies but requires maximum development and maintenance effort.
LINQ to SQL
LINQ to SQL provides a simple mechanism to access SQL database and keeps development effort to minimum, but not suitable for complex data structure. Query performance generally will be slower compared to SQL client.
Entity Framework
Entity Framework provides a balance between LINQ to SQL and SQL client. It supports complex data mappings and by implementing proper Repository pattern, we can abstract the storage mechanism from business layer easily.
Selected Approach
Based on the above observations (in particular: support for complex data mappings; and simpler implementation) the proposed solution is to use Entity Framework for data access.
Note: The above description was written few years ago and may not be up-to-date. Thought it might help.
System.Data classes are need to detailed management data storage of your app. System.Data.Entity or Linq to SQL its more simply to using in small projects.

Possibilities of SQL Injection with EFCTP and .net mvc

Just want to know from experts that is there any inbuilt security for SQL Injection in Entity Framework or .net MVC?
Thanks
It is only built in if you use it. Entity Framework provides strongly typed entity classes - if you only use Linq to Entities you will be protected against SQL injection attacks, the same is true though if you use parametrized SQL with SQL server directly.
Having said that, you can still shoot yourself in the foot if you use EF store queries - this can be plain old SQL - so make sure you use SqlParameter here.

How to call stored procedures from mvc3?

I'm trying to use mvc3. The online documentation says how to connect one class to one table. anybody have a suggestion on how to run stored procedures and return the results to a view?
MVC is not responsible for the way you access your data. There are many technologies that you can use including
Plain old ADO.NET
LINQ to SQL
NHibernate
Entity Framework
LINQ to SQL is probably the easiest way to get it working without any prior knowledge. Check out Scott Gu's post http://weblogs.asp.net/scottgu/archive/2007/08/16/linq-to-sql-part-6-retrieving-data-using-stored-procedures.aspx

Is EntityFramework using linqtosql underneath?

I am quite new to entity frame work 4.0 and what I know from my intial analysis is entity framework is nothing but an abstraction of ado.net with its storage model, conceptual schema and the mappping between these two.But one thing I am unclear is while fetching data from database or executing any stored procedure what mechanism its following.
Is it adopting the traditional ado.net approach or is it the concept of linq2sql?
The reason I am asking this question is in our project we are not suppose to use linq for some security reason (I am not sure what this security linkage is but we have not to follow linq relegiously).
So I just wanted to know how entityframework works for performing all its db transaction and whether by any chance it is using linq to sql?
Hope I was able to convey my problem. Please look into this and respond ASAP. I am in a kind of fix :(
Regards
Subrat
No - both Linq-to-SQL and Entity Framework make good use of the LINQ features in C#/VB.NET - but they're both totally separate projects.
Linq-to-SQL was created by the C# team, more or less as a "proof-of-concept" for how to use LINQ with databases.
Entity Framework on the other hand grew out of the database teams (ADO.NET team) at Microsoft and was designed from the ground up as a full-fledged, enterprise-ready system to be the "next big thing" after straight up ADO.NET
Why using LINQ (as a technology) should have any security implications is beyond me.....
Yes - with the Linq-to-SQL approach, your application needs direct access to all underlying tables - read and write. But with EF in version 4, you can do very safe styles of work:
SELECT only from views exposed in the database
handle all the CUD operations (INSERT, UPDATE, DELETE) by wiring up your EF entities to stored procedures
With this, your applications don't need direct table read/write access at all - no different than when manually using SELECT from views and stored procedures for all other operations.

Resources