Perform pure sql query using Fluent NHibernate in asp.net mvc4 - fluent-nhibernate

how to perform a pure SQL join query using Fluent NHibernate and send the result to the view from controller in asp.net mvc4

You may use the HQL query interface of nhibernate. The HQL language is designed to be independent of database provider.
All common joins can be expressed in HQL. Please read chapter 14 of the nhibernate documentation (with examples at chapter 14.12).

Related

Can I use SQL Queries instead of Entity framework in .NET Core clean architecture?

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

NHibernate LINQ Or HQL

I have heard about 2 way of querying using hibernate:
NHibernate.Linq and HQL
NHibernate.Linq or just HQL witch is faster?
Do any one have any other advantage?
I don't know Linq to NH that well. Technically is Linq to NH turned into HQL behind the scenes. It provides editor support (auto completion) and compile time validation (e.g. when typo) in contrast to pure HQL, which appears as normal strings to the developer tools.
Similar is QueryOver the successor of Criteria.

linq to sql, why to use it in MVC instead of traditional queries?

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

Spring JPA: Query builder versus Criteria Builder , which one to use?

I am going to start new project that would play with very large database, thus would be having lots of database operation.
I have decided to use Spring JPA as my ORM. Now Spring JPA provides various techniques to use in DAO layer. I am confused between Criteria builder and Query DSL. Both seems to solve my problem well and I guess there is not point using both of them in a same project because they provide same functionality.
So now which one to use and why ?
The JPA 2 Criteria API and Querydsl are equivalent in functionality, but Querydsl has been designed to be more fluent and look more like JPQL/SQL. So it can be used as a replacement for both JPQL and JPA 2 Criteria.
Here is also a blogpost on the topic which shows how compact Querydsl queries are in comparison to the JPA 2 Criteria API Querydsl as an alternative to the JPA 2 Criteria API
This answer is biased, since I am behind Querydsl.

Is there an abstract ADO.NET interface that declares pagination?

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.