Access DB from C# using System.Data.Entity but NOT EF - asp.net

My company has an older ASP site that looks like it's written using model-first EF pattern... Except there are no references to EntityFramework.dll anywhere. Talking to the original coder, it doesn't seem he actually knows how he got it to work. He though EF was in the System.Data.Entity namespace as it comes in the framework.
How is it that he was accessing a database (DB2) using models/entities but not actually referencing the EF anywhere ?

As the documentation from MSDN for System.Data.Entity:
The System.Data.Entity namespace contains classes that provides access
to the core functionality of the entity framework.
To access a database without Entity Framework, you can use ado.net. It is the first level of data access and you should learn it before using any ORM tool. Check the namespace System.Data.SqlClient to have types to access Sql Server database. If you check each type, you will see there is a common convention to implement a ado.net data access in .Net. WE have DbConnection, DbCommand, DbTransaciton, IDataReader, etc. All these common types you can see in System.Data.Common.
For the DB2 database, you can download the .Net Provider for data access with Db2 in this link because it is not native provider. It is the same way as you do for other database, but use the specific .Net Provider.

Turns out that EF 4 was initially released as part of .NET 4.0. Only since EF 4.1 was it separated into its own package.

Related

Configure database for MVC authentication

I've been Googling terms like
configure database for mvc authentication
But I can't find anything from this decade that relates to my configuration.
I've created an MVC application using .NET Framework 4.6 with authentication support (database first). Now where do I find step-by-step instructions for creating the database tables and configuring MVC to use them?
Thanks for any tips!
The correct thing to google for is 'ASP.NET Identity'.
If you generate an MVC app straight from one of the templates it will generate a number of classes to handle security and identity.
One of these classes will implement interface IUserStore. The class provided will inherit from Microsoft.AspNet.Identity.EntityFramework.UserStore<TUser>, and uses Entity Framework to check the database if the tables exist, and create them if they are not there.
If you are uneasy about giving your application enough privileges to modify your data schema (ew!), you can create your own class that implements IUserStore and plug that into the system.
It's a big topic, but hopefully this is enough to get started with.

Difference between Entity Framework and Microsoft SQL Server

I'm fairly new to mvc, asp.net, and .net framework in general.
I understand what models are, controllers and views, but what I don't get it is Entity Framework. I developed websites before using php, and when I needed to store some data I simply do that using MySql databases. I thought this is the case with asp.net, same concept but instead of MySql, Microsoft Sql server is used. Now I started to learn .net framework and I watched a lot of online tutorials and saw them using some classes inherited from DbContext to store data! Can anyone tell me where these classes store the data and why don't we use Microsoft Sql server instead?
Entity Framework is an Object Relational Mapping tool (ORM), a layer that sits between your database and code. The idea is that the ORM is database agnostic and will handle writing the SQL for you, so that you could (in theory) swap between SQL Server, MySQL, or whatever database you want with only configuration changes.
You can skip Entity Framework and use SQL directly with ASP.Net. Your tutorials just happen to use Entity Framework.

Asp.net Web API With No Entity Framework

We want to start using Asp.net web api for our future enterprise services however we do not want to use EF for data access.
Are there any samples out there for Asp.net Web APi working with regular ado.net classes instead of EF?
Thanks.
Are you looking for code samples for how to use e.g., SqlConnection, SqlCommand, SqlDataReader?
You would use the classes in System.Data.SqlClient if you are trying to talk to SQL Server, System.Data.OracleClient if you're trying to talk to Oracle, or System.Data.Odbc if you're trying to talk to MySQL.
Here are some code samples for how to call a stored procedure from ADO.NET. Good luck!

ASP.Net: ASPNETDB can I implement LINQ to Sql with this DB?

Very new to membership provider and just implemented on my new web site. I thought it would be nice to be able to use LINQ to query the database. Can I implement LINQ to SQL on that database?
You shouldn't really be querying the database directly. There is a Membership API for that. It uses a pattern called the provider model which means that you can use the same API always and then swap out a different membership provider without having to change your site code.
You might want to do this to use an xml file, or a webservice, or an in-memory provider, but you should still be able to use the Membership API without having to worry about how the data is being retrieved.
If you do want to write some linq-to-sql code then you should write your own membershipprovider:
http://www.google.co.uk/search?q=asp.net+custom+membership+provider
BTW, If you are just getting started then you should be learning Entity Framework really because Linq-to-Sql has been kind of superseded by EF.
All the things rtpHarry said are right, generally you would use the membership API whenever you are within your ASP.Net application.
However, if you are querying your membership DB from another application for some reason, for example if you had a WinForms admin application or something, then you certainly can use Linq to SQL (or Entity Framework).

Entity Framework Vs Data Access Layer

I want to know list of advantages of using Entity framework over data access layer.
My website is host in shared hosting and i don't have access to IIS
Considering that i am working shared hosting world, is it feasible to work with entity framework?
Microsoft has publicly stated that Entity Framework will be the preffered data access technology for the .NET platform. Given your experience I feel like Entity Framework would be a huge asset to your ability to rapidly develop applications. Shared hosting is completely irrelevant to the fact that you are using entity framework. Just make sure that the hosting company supports .Net 4 framework (or w/e framework version you work with).
Entity Framework is a data access layer. Specifically it's an Object Relational Mapper.
So it basically comes down to - do you want to write your own DAL? - or would you rather spend your time building out the Data Model, and then having Entity create your entities and classes, etc.. for you.

Resources