Is it mandatory to use Linq when using entity framework? - c#

I am using entity framework for my project. I just started reading about entity framework. Is it necessary to use LINQ? When I am looking at this website, it does not use LINQ anywhere. So, are there two ways of using EF- with and without LINQ?
link to the tutorial
http://www.entityframeworktutorial.net/EntityFramework4.3/Introduction.aspx

Quoting from "What is Entity Framework" in the link you provided:
The Microsoft ADO.NET Entity Framework is an Object/Relational Mapping
(ORM) framework that enables developers to work with relational data
as domain-specific objects, eliminating the need for most of the data
access plumbing code that developers usually need to write. Using the
Entity Framework, developers issue queries using LINQ, then retrieve
and manipulate data as strongly typed objects. The Entity Framework’s
ORM implementation provides services like change tracking, identity
resolution, lazy loading, and query translation so that developers can
focus on their application-specific business logic rather than the
data access fundamentals.

Its not mandatory to use LINQ while using entity framework.
But it would make things easier if you know the syntax of LINQ and take advantage of functionality it gives.
Is it possible to use Entity Framework without LINQ?
http://forums.asp.net/t/1948335.aspx?Can+I+Learn+or+Use+Entity+Framework+Without+Knowing+LINQ+To+SQL+

Related

What's Different Between LINQ and Entity Framework?

I know the benefit of the LINQ and I know use of it in .Net Application. I fill same thing there are providing as a Entity Framework.
So What's Major Difference between LINQ and Entity Framework?
LINQ could be applied to any data source: in-memory objects, XML, SQL, ...
Entity Framework could use LINQ to perform queries against a relational database.
LINQ to SQL is the predecessor of Entity Framework and is obsolete now.
Comparing EF and LINQ is incorrect. Both are different things and they often work together to give better developer experience (and productivity benefit).
LINQ is querying syntax/model that can be applied to any data source. EF provides one such data source.
They are somewhat similar, and can be used in a very similar way, code-wise, but they have some important differences. Note that "LINQ" is not the same thing as "LINQ to SQL"; the EF also uses LINQ. Some notable differences are:
LINQ to SQL is largely SQL Server only, not so much by design as by implementation. The EF is designed to support, and does support, multiple DBs, if you have a compatible ADO.NET provider.
Out of the box, LINQ to SQL has a very poor story for DB metadata changes. You have to regenerate parts of your model from scratch, and you lose customizations.
The EF supports model features like many-to-many relationships and inheritance. LINQ to SQL does not directly support these.
In .NET 3.5, LINQ to SQL had much better support for SQL-Server-specific functionality than the EF. This is mostly not true in .NET 4; they're fairly similar in that respect.
The EF lets you choose Model First, DB First, or Code First modeling. LINQ to SQL, out of the box, really only supports DB First.
SOURCE : Here
I totally agree with VinayC. You cannot really compare.
With Entity Framework, you will be able to have a whole representation of your database in your program. It will help you create classes corresponding to the database elements, connected together like they are in the database. You can after interact with elements of theses classes directly, and like this impact the database. You will have some representation of these classes diagram in visual studio. It's basically often simpler than working directly with the database elements, even if setting it up requires some effort.
The use of Linq is to perform queries on the data sources.

Linq-to-SQL vs Entity Framework in database-first approach

I got confused on what are the differences between Linq-to-SQL and Entity Framework when following the database first approach as I can not find any clear differences.
In my case when I was using Linq-to-SQL I used to create the tables then I use Linq-to-SQL to create the classes that represents the tables, and now when I switch to Entity Framework I am still following the same steps (creating the database tables then create the associated classes using EF).
And I am interacting with these classes on the same way, for example I used to query the User class using the same syntax and approach but one time when the User class was created using Linq-to-SQL and the other time when it was created using EF, so where is the difference ?
public IQueryable<User> findstudents(string term)
{
return from student in entities1.Users
where student.UserID.Contains(term)
select student;
}
Second question if I use EF to map the tables into classes, is it still possible to use Linq-to-SQL in the same application to query the EF classes?
LINQ is a base technology - that's the syntax that gives you the SQLish query options in C# - that's totally independent of whether you use Linq-to-SQL or EF. So if you want to query your data classes using the LINQ syntax - you can do that with both frameworks - but once you use Linq-to-SQL and once you use Linq-to-Entities. You cannot use Linq-to-SQL against an Entity Framework EDMX model.
Linq-to-SQL is great
if you need very simple 1:1 mapping - one table equals one class in your domain model
if you never need anything else but SQL Server (Linq-to-SQL doesn't support anything else)
if you want to be up and running really quickly
Entity Framework on the other hand
supports multiple backends (SQL Server, Oracle, Firebird - other will likely follow)
supports a full conceptual data modelling strategy - you define the physical model in the database, the conceptual model in your app, and the mapping between the two
gives you the ability to handle things like mapping a single business entity to several tables
support table-per-hierarchy and table-per-class inheritance scenarios
support refreshing/updating your model (EDMX file) from the database when things change (in Linq-to-SQL, you basically have to drop + recreate those entities involved - thus loosing all your customizations you might have made)
In brief: Linq-to-SQL is a great, simple and lean'n'mean ORM for SQL Server - use it, if it does all you need. Entity Framework is quite a different beast, much more capable, but also more complex, much bigger - perfect for your next enterprise-critical app, but probably overkill for your personal blog app :-)
If you want to create something that's "future-proof" and will use the OR technology that Microsoft is pushing into the future, then you should go with Entity Framework. Especially in v4, it's also a lot easier to use, a lot more slimmed down and more useful than ever before.

What can be mapped to the entity framework?

What is the utility of the Microsoft Entity Framework? EF allows me to map entities to databases (tables). I it possible to map entities to other queryable system?
I think of web services, specific calls to other system, exe, files, ...
Entity Framework is an ORM (Object-Relational Mapper) so it's specifically meant to work against relational databases.
You can use still use LINQ (which is what I suspect you're really after) against other data providers like WCF, OData, etc.
Entity Framework is based on ADO.NET, so it can be used with anything that has an ADO.NET Data Provider.
Here is a link to the official ADO.NET Data Providers.
http://msdn.microsoft.com/en-us/data/dd363565.aspx
If you wanted to use it with an exe or web service, you could if you wanted to go through the effort of creating an ADO.NET Data Provider. However, this does not seem like a reasonable thing to do.
As others have mentioned, EF is an ORM for databases. You could hack together providers for "other queryable systems", but that's not what its designed for.
LINQ providers, however, such as LINQ to XML and LINQ to objects, allow you to query (but not write to) just about anything that can be represented as a collection.

Need Advice: Switching from Linq to SQL to Entity Framework

I know the high-level differences between linq to sql and entity framework, however, I am hoping for advice from someone else who has already made the switch themselves, or has sufficient experience with both. Coming from a strong linq to sql background, as far as implementation and low-level details, are there any important things I need to know as I start coding my new data access layer project with entity framework?
I already created my edmx file (I chose the database-first approach), and everything just seems suspiciously identical to linq to sql so far. What would help me is a short list of items, like, in linq to sql, you do [this] [this way], but in entity framework, you'll want to do it [this way].
Sorry if this is a strange question, but any attempts at answers would be greatly appreciated. Thanks!
In new project between L2S and EF I suggest EF (consider Entity Framework version 4.0 or superior, DON'T use early EF releases).
While Linq to SQL is a class to table mapping EF 4 is a complete ORM (Object Relational Mapping) tool with different mapping scenarios.
With EF you have a lot of flexibility:
Database First approach
Model First approach
Code First approach
and a strong integration with LINQ Provider.
Unit testing with Linq2SQL is a nightmare.
With EF you have POCO (Plain Old CLR Object) classes out of the box. In L2S the entity class is tight coupled to the L2S namespace.
EF can help you also in Domain Driven Design scenarios.
Microsoft consider now EF the first database access method and it's the base for other services like RIA services or MVC database scaffolding.
LinqToSql is now the first database access methodology only in Windows Phone scenarios.
NH is far better... but again as EF is microsoft baby, it will grow as time goe

Persistance Ignorance Linq to SQL

I have an existing domain layer. I want to develop the persistence layer using Linq to SQL. I am currently using an external map file. I am trying to use lazy loading for my child collections but am unsuccessful. Is there a way to implement lazy loading using Linq to SQL but without using EntitySet or EntityRef.
I can't guarantee that I'm up to the latest development of LTS, but previously you had to you use EntitySet/EntityRef to get lazy loading.
You're best bet is NHibernate if you want a PI-model.
(Not really answering the question.)
Entity Framework (aka. LINQ to Entities) in .NET 4 includes persistence ignorance support e.g. being able to map to POCO (Plain Old CLR Object1). See "Sneak Preview: Persistence Ignorance and POCO in Entity Framework 4.0 ".
1 I.e. Not requiring a base class or attributes.

Categories

Resources