ASP.NET LINQ Database vendors - asp.net

Will Linq work against any database (i.e) MySQL,Sybase,Oracle,DB2?

It depends what you mean by "LINQ".
LINQ to SQL will only work against SQL Server and SQL CE (or whatever it's called these days).
I believe that the Entity Framework (LINQ to Entities) will work with any database supported by ADO.NET... but I think that vendors can give more specific support which would no doubt mean better performance and quite possibly a wider range of translatable queries.
Then there are efforts like LINQ to NHibernate which again will work with any ADO.NET-compatible database.

LINQ supports only SQL Server.
However there is a LINQ provider for My sql here
Also, check this resource for more info.

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 analyse LINQ queries

I swear I've seen how to do this before, but now that I actually need to do it I can't remember where I saw it at. I need two different things --
1) to see the actual SQL query that is generated by a LINQ query and
2) when the SQL query actually hits the database to do whatever (CRUD operations)
Is there a tool that will allow me to do this?
EDIT:
Sorry, should have given more detail.
-- LINQ to Entities is what I'm using.
-- Also, I don't have admin rights on our instance of SQL Server, so I can't use SQL Profiler. I could always call the DBA and have them do it for me, but it's a hassle. I should have mentioned that and I apologize. What I really want is a tool that I can use on my own box that will allow me to see when a LINQ query hits the database while I am in debug mode (debugging and stepping through the code).
Try using SQL Profiler. It's great for seeing what LINQ to SQL is generating.
SQL Profiler is a graphical tool that allows system administrators to monitor events in an instance of Microsoft® SQL Server™. You can capture and save data about each event to a file or SQL Server table to analyze later. For example, you can monitor a production environment to see which stored procedures are hampering performance by executing too slowly.
LINQPad is also a great tool for writing linq and sql statements for testing.
LINQPad compiles your queries using .NET's CSharpCodeProvider (or VBCodeProvider). Because C# and VB are statically typed, any database objects that you reference need the backing of a typed DataContext. For performance, LINQPad builds typed DataContexts on the fly using Reflection.Emit rather than generating and compiling source code. It uses LINQ to SQL rather than Entity Framework because LINQ to SQL is an order of magnitude faster in building the metamodel when instantiated.
The .ToString() on the IQueryable for LINQ to SQL will show you the query.
var myquery = from x in dbcontext.MyTable
where x.Prop1 == someValue
select new {
value1 = x.prop1,
value2 = 5,
};
var sqlstring = myquery.ToString(); //<= look in this string
There are a few tools that can help.
L2SProf (Linq2Sql Profiler) is a for pay tool that can do a lot to help you see and optomize your queries. http://l2sprof.com/
LinqPad is a great tool for write linq to sql queries and seeing the sql that comes out. It also lets you write c# code just to experiment with things. It's a great coding scratch pad. There is a free version, but you get extra features if you pay. http://www.linqpad.net/
Otherwise, there are instructions here for viewing the generated sql for free with builtin stuff: http://msdn.microsoft.com/en-us/library/bb386961.aspx
Using Visual Studio 2010, turn on IntelliTrace and you'll see every request for LINQ To SQL, LINQ To Entities and generally everything that ultimately uses ADO.NET.
Are you looking for the DataContext.Log property? (I'm assuming you're using LINQ to SQL.)
You could create a TextWriter which dumped a stack trace and timestamp every time it was written to, which would give you the timing information.
depends entirely on the ORM. Most ORMs offer some sort of Log property you can plug a TextWriter or so into. Consult the docs for ORM to learn more.
In general: when you use some sort of SaveChanges method. This ties in with (1), the logger will provide you with the information.
Here is a solution, it is very complex: http://blogs.msdn.com/b/jkowalski/archive/2009/06/11/tracing-and-caching-in-entity-framework-available-on-msdn-code-gallery.aspx

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?

Does sqlite support linq-to-SQL?

Does sqlite support linq-to-SQL?
No database supports LINQ. LINQ is an abstraction layer on top of the database so it depends on the ADO.NET provider. LINQ-to-SQL is also bound to SQL Server.
That being said this SQLLite provider has support for LINQ to Entities.
There's a third-party library called LinqConnect that is aiming at providing Linq-to-SQL support to a variety of database backends - including SQLite.
There's also IQToolkit, which does nothing other than reimplement all of LINQ-to-SQL in open source. This is great if you want "raw" access to your database. IQToolkit Contrib could be handy too if you go this route.
If you're more of an ORM type, you could look at SubSonic (which is built on IQToolkit).

Are there any linq-to-sql for Databases other than MS-SQL?

I am wondering if it is possible to use Linq functionality to connect to a database like my-sql
If it is possible are you able to use the designer to created the DataAccessLayer like with MS-SQL or do you have to hand code its content.
Thanks in advance.
KJ
Linq to Sql only works with MS-SQL. Entity Framework can access several different database back ends and it fully supports linq. NHibernate can access more databases but it's linq support is not yet complete.
You could use IQToolkit.
Yeah check this out
http://code.google.com/p/dblinq2007/
There has been a few posts just recently on this too, just search on stackoverflow for more details.

Resources