I'm implementing a DAL library that is database vendor neutral. Is there an abstraction in ADO.NET (System.Data) for describing pagination? And, do some vendors' ADO.NET provider implementations support such an interface so that I don't have to manually tool up the customized SQL syntax?
ADO.Net has no support for pagination. LINQ2SQL has, because the Skip and Take operators are implemented by the SQL provider using the ROW_NUMBER() functions. Entity Framework supports SKIP and LIMIT in its Entity-SQL syntax and also the LINQ operators for Linq2EF, see How to: Page Through Query Results (Entity Framework).
The LINQ2SQL methods are specific to SQL Server, however the EF methods are 'generic', as long as you're willing to use EF instead of the old ADO.Net methods.
Paging is very platform-specific, because it requires you to retrieve the correct 'page' of data from the database.
Unfortunately, I don't think there is any SQL standard for retrieving those pages.
Related
I would like to have statically typed LINQ expressions that produce SQL to be executed on the database. Unfortunately it seems entity framework core is very limited with regards to union and group by. Is it possible to use another library, e.g. LINQ-to-SQL purely for querying, that uses the statically typed entity classes we already have rather than hand-crafting SQL?
I've settled for using LINQ to DB thanks to this comment.
We're using the same entity classes we use for entity framework for the queries, and to ensure the table names are correct we use the C# nameof operator, e.g. nameof(EFContext.UserTasks). This should allow us to be fairly sure our queries still work even after renaming properties/tables.
While researching about the clean architecture of .NET Core, I understand that only Entity Framework is being used.
I wanted to know whether we can use raw SQL queries by making a connection to SQL with connection strings.
Clean architecture doesn't restricts you to entity frame work. You can also look into micro ORM e.g. Dapper which can be used to write sql queries. It's very powerful and gives you many out of box capabilities e.g. mapping. Infact if you don't want full ORM functionality Dapper is recommended in Microsoft docs.
Dapper
Dapper for read queries
If you read this EclipseLink's User-/Developer Guide it doesn't mention whether the TABLE and COLUMN functions are database independent and I'm not sure at all if i should use them considering that i'm working with some oracle, postgres and sqlserver databases.
Question
Are these functions DBMS independent?
The very first sentence of that UserGuide gives a an important piece of information:
The Java Persistence Query Language (JPQL) is the query language defined by JPA. JPQL is similar to SQL, but operates on objects, attributes and relationships instead of tables and columns.
That is, JPQL != SQL in a strict sense. JPQL is a query language for the purpose to query object in an environment of an object relational mapper (ORM). In this context, an ORM abstracts the actual DBMS ("the SQL world"). EclipseLink fully implements standard JPQL as defined in the JPA specification documents (versions 1, 2.0, 2.1, 2.2).
Moreover, EclipseLink
provides many extensions to the standard JPA JPQL. These extensions provide access to additional database features many of which are part of the SQL standard, provide access to native database features and functions, and provide access to EclipseLink specific features. EclipseLink JPQL extensions are referred to as the EclipseLink Query Language (EQL).
What does this mean for
COLUMN operation to allow querying on non mapped columns, and
TABLE operation to allow querying on non mapped tables?
EQL is an extension of the basic ORM implementation of EclipseLink to provide you an enhanced way of querying objects and meta-information of their corresponding database columns. This is implemented specific for each vendor - depending on the configured JPA dialect - OR as vendor-neutral as possible.
In essence, it should be safe to use these functions as far as different DBM systems are concerned. Still, you will bind your application to EclipseLink once and for all, robbing yourself the possibility to switch to different JPA providers, e.g. Hibernate, in case you want to experiment or for reasons of performance.
Hope it helps.
is it necessary to use LINQ for sql purposes in MVC ? can't we use traditional queries like:
Select name from tbl where id = 2;
instead of LINQ ? and why linq in any case ?
ASP.NET MVC in no way restricts your choice of data access technology. In fact, model binding works with objects, and MVC has no idea whether your objects represent some database or not.
Besides, if you were to use LINQ at all, you would do best to use Entity Framework (a.k.a. LINQ to Entities) and not LINQ to SQL, which is much more limited.
Linq to SQL, EntityFramework, nHibernate - are ORM (Object-relational mapping) tools. ORM represent database objects as standard .NET classes.
Raw SQL can be used, when you are inserting a lot of data, and you need a good performance. In all other cases you should to use ORM.
And if you decide to use ORM, I advise you to use EntityFramework; it's more powerful than LINQ to SQL.
You don't need to use linq at all. I usually use dapper.net for my data layer, mapping SQL queries to objects. It's personal preference.
You are not obliged to use Entities Framework, as you are not obliged to use anything in particular.
Microsoft strongly suggests using the Entities Framework because it is an ORM integrating very easily with the whole Microsoft ecosystem, using the LINQ query language which is integrated in the .NET languages specification. This integration happens through the Linq to Entities query language and the respective tools provided in Visual Studio.
As you will see, Entities Framework (as every other ORM) has the overhead of the learning but in my opinion, it totally pays you back as using an ORM leads to faster development and more maintainable source code. I would strongly suggest using an ORM (it has many advantages) and I suppose since you are already familiar with Microsoft ecosystem, Entities Framework would be the best choice.
Hope I helped!
Well, if you want to use this style of queries you can use stored procedures this is to close to the normal query, just and a Linq-to-SQL file into your project and drag and drop you stored procedures then you can use them like methods and this is a link http://msdn.microsoft.com/en-us/library/bb386946.aspx
Note that Linq-to-SQL is integrated only with SQL Server
No, you do not have to use LINQ at all, or any other ORM frameworks, you an work directly against a database.
In .Net this is typically done using ADO.Net, for example using the System.Data.SQL namespace.
See code examples and official documentation here
My Company is working with a Database called U2 Universe.
The Database Manufacturer provided us with a ADO.Net provider which works with Microsoft's Entity Framework.
Is it possible to extend NHibernate to make it work with the ADO.Net provider?
Thanks.
Of course it is. You need to implement IDriver and Dialect (you can use GenericDialect, but it's usually too limited)
For examples, look at the source of existing drivers and dialects.