What can be mapped to the entity framework? - c#

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.

Related

What is the advantage of mapping relationships in Entity Framework without mapping in the table

I have seen that in some systems, relationships are mapped in Entity Framework without being mapped in the SQL tables. What is the point of using Entity Framework to map relationships over mapping them in SQL?
Real answer? No good reason unless you need them in the app, and you don't control the database, and it doesn't have them.
Generally, instead of that, it's a developer who's assuming that "the app does that" in terms of relationships, and also assumes that no other app or process will ever touch that data.
Here's a blog post on the latter: https://blog.greglow.com/2016/05/31/should-my-database-have-foreign-key-constraints/
First, If you use Entity framework in large system, it will reduce much code.
Second, we don't need to concern about how to connect to database.
Third,Entity framework can be used as infrastructure for data services and OData services.

Is it mandatory to use Linq when using entity framework?

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+

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.

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

Categories

Resources