Connecting to the database SQL Server for beginners - asp.net

Just like to ask, I want to create a blog with ASP.NET as a practice to get better. I came from PHP btw.
Anyway I'm stuck because I don't know what's the way most .NET programmers use to connect to the database. I'm planning on using LINQ.
Any tutorial/books and also websites that would point me to the right dorection would really help. Thanks a lot!

The way most .NET programmers use to connect to databases is ADO.NET, included with the Microsoft .NET Framework. Here some useful code examples.
LINQ ist not designed as a replacement for ADO.NET, LINQ provides a uniform programming model for any kind of data. With it, you can query and manipulate data by using a model that is independent of data sources.
var query =
from c in Customers
where c.Country == "Usa"
select c.CompanyName;
foreach (string name in query)
Console.WriteLine(name);

.NET developers use ADO.NET to connect to relational databases. This is the low level API. Entity Framework provides an ORM on the top of ADO.NET that could map relational tables to objects.

If you are new i will advise you to start with linq, but before that you should learn a little bit about ADO.Net, and whats better then msdn tutorials:
ADO.Net:
http://msdn.microsoft.com/en-us/library/h43ks021%28v=vs.71%29.aspx
http://msdn.microsoft.com/en-us/library/cc161165.aspx
Linq:
http://msdn.microsoft.com/en-us/library/bb386964.aspx
http://www.codeproject.com/Articles/246861/LINQ-to-Entities-Basic-Concepts-and-Features

Related

Entity framework or just SQL queries

I'm doing a project with ASP.net core. I found that most of developers use Entity Framework for dealing with the database. I have worked with raw SQL queries with ASP.NET. I'm using SQL SERVER 2014 and have to develop a RESTfull API to deal with my database. My database consists of about 50 tables.
So my question is, what method is better for my task, using Entity Framework or using raw SQL queries?
From my research I have found that Entity Framework has basically two methods, Code first and Database first. I have looked into both methods. I need to know pros and cons of using entity framework compared to normal SQL queries.
And finally is there a effect on .net core with entity framework?
It seems that you have a large application, my recommendation is that you should use Entity Framework because you have LINQ. (Examples here: http://www.entityframeworktutorial.net/Querying-with-EDM.aspx).
With LINQ you can build your queries using methods instead of strings.
With LINQ:
var L2EQuery = context.Students.where(s => s.StudentName == "Bill");
With Native SQL:
var studentName = ctx.Students
.SqlQuery("Select studentid, studentname, standardId
from Student
where studentname='Bill'")
.FirstOrDefault<Student>();
Using entity framework with code first migrations and a decoupled from ef repository pattern architecture does not restrict you from using sql queries as well sometimes when you need to.
Your question will be closed because it is too opinion oriented.
But yes, personally, I greatly encourage the use of Entity Framework.
The thing is, if you have no experience at all in EF, then you will be subject to a learning curve. Which means it will still be easier for you to simply use SQL query in your code. That said, if you take your time and learn correctly how to use EF it will probably be of good use later.
I've experienced both Entity Framework and raw SQL queries, and now that i'm used to EF, I find it much better.

How to use LINQ in SQL Server and C#?

I want to use LINQ in ASP.NET to make the performance fast with the quick access to SQL Server 2008.
I want to know how to use the Linq queue in C#. So I can perform all Linq query in my project.
This page is your friend, study it :)
101 examples of linq used in simple, yet extensive ways, should be no problem expanding on this
http://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b
Good answer for a badly structured Question I suppose

Best way to setup the database connection for my ASP.NET app?

I'm a beginner with ASP.NET coming from a PHP background.
I'm planning on creating a database driven application but I was wondering after creating my DB structure using the free SQL Server Express, what is the best way to connect to my database?
I'm wondering if there's any tutorial on the best and most professional approach to do this. This would really help me a lot and get me started. Thank you in advance!
The best and most professional approach would be to use a ORM. My favourite ORM's for .NET are (in no particular order):
Fluent NHibernate - walkthrough
Dapper - stackoverflow examples question
Entity framework - Microsoft's own ORM
If your just starting out Dapper is great. You just run a SQL statement against a connection and Dapper takes care of mapping the results to a class for you. Dapper is used by stackoverflow BTW.

using linq and entity framework to iterate over database data

I read that in some books they use linq to sql and entity framework..
Whats so good about them?!!?
They are slow.. especially linq to sql. Does entity framework have any benefit that make it worth learning?!?
I strive to make the site as fast as I can, and I dont use disconnected data access much
consider that my goal is to make the site run as fast as it can
ORM frameworks like Linq-to-Sql and Entity Framework will almost always implement an abstraction layer between the program code and database SQL statement. This layer's job is to parse the code's syntax into a SQL statement.
So, if your ultimate goal is increased speed, it would be smart to avoid that layer.

What is a good alternative to SQL Server for ASP.NET applications?

I've been looking into a lot of database's recently, and am not sure if it's because I'm bored or what, but I want to create a few web applications using database's other than MS SQL Server. Any suggestions that tie into ASP.NET nicely?
I'd recommend VistaDB and MySql.
I'd consider MySQL as the obvious alternative.
However, fundamentally one relational database is pretty much the same as another, more so when accessed through something like ADO.NET. If you're bored with SQL Server then rather than looking for an alternative why not look at trying different data access strategies?
You don't mention whether or not you're using an ORM (object relational mapper) which can make working with databases a lot more enjoyable than using standard ADO.NET, such as:
NHibernate
Entity Framework
Linq to SQL
Subsonic
IMO, sticking with SQL Server but trying out a few different ORM's would be much more interesting than switching to a different database altogether.
Or how about looking into using a document database, such as RavenDB?
I suggest you take a look at Connectionstrings.com. Most databases there have a .NET provider available.
Define "good".
Do you want to have a database as a simple data store, or should the database also implement business logic (stored procedures, triggers)?
Do you want to ship your apps and therefore require easy of installation?
Does it matter if the database is commercial, when MSSQL offers a free version?
As #richeym pointed out: are SQL statement a sufficient interface, or do you require an ORM?

Resources