Code Monkey home page Code Monkey logo

sql2linqconvertor's Introduction

SQL2LINQConvertor

Hi I am Ganesh Kamath. I have stopped working on this project and have moved on to a different company.

I have created a basic SQL to LINQ convertor which I hope to see compete in converting SQL to LINQ as the project progresses.

Between December 19th and December 30th, I has asked permission to work on this SQL To Linq Convertor at work. I want my 2 week old project to gain more contributors over time in order to help others like me who might be looking for a solution. I want this code to act as a plugin where user can paste SQL on the Left Hand side to see LINQ on the Right Hand Side on the click of a button.

As of now the code is written to handle simple Select statements.

Feature List - only simple select statements:

  1. Column name is specified from single table.
  2. Column name is specified from Join Tables.
  3. Where Clause is written with simple logical check separated by And
  4. user defined columns mixed along with Table defined columns
  5. simple Case-When-Then-End condition
  6. Order by when single condition is used.

Work pending - handle more complex SQL:

  1. Handle nesting
  2. Handle sub queries
  3. Handle advanced queries

Environment Setup:

  1. Visual Studio 2015 Community Edition
  2. Microsoft Modelling and Visualization SDK
  3. Entity Framework 6 and EF6 Tools

Add 2 environment Variables:

  1. Add the following path to Path, so that the TextTransform.exe path is recognized: C:\Program Files (x86)\Common Files\Microsoft Shared\TextTemplating\14.0\
  2. Add the following

[Variable] VS140COMNTXTTRANSFORM

[Value] C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes

Remove the first line from the following file:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes\EF6.Utility.CS.ttinclude

Otherwise it gives error (I dont remember the error or the line that was there).

Preferable run as administrator.

sql2linq

I came across several complex SQL Queries with Subqueries and Group by clauses which I aim at implementing some time from now. But for the purpose of early feedback I will be posting my code as it is (by chaning very few details in the code in order to generalize). I have explicitly verified from our company regarding posting this code.

Feel free to fork a copy and make the changes relevent to your application.

sql2linqconvertor's People

Contributors

ganeshkamath89 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

sql2linqconvertor's Issues

Group by clause is not handled by the convertor

Need help in addressing Group By clause used in SQL to Linq.

Example:

SQL:

SELECT
*
FROM
(SELECT
*
FROM
(SELECT
CMN_BANK_LOAN.ID,
CMN_BANK_LOAN.LOAN_DATE,
CMN_BANK_LOAN.REPAY_DATE,
CMN_BANK_LOAN.AC_ID,
(
CMN_ACCOUNT_MASTER.ACCOUNT_NO + ' : ' + CMN_ACCOUNT_MASTER.BANK_NAME
) AS AC_NO,
CMN_BANK_LOAN.BY_WHOM,
CMN_BANK_LOAN.TOTAL_AMOUNT,
SUM(CMN_BANK_LOAN_PAY.AMOUNT) AS PAID_AMOUNT,
CMN_BANK_LOAN.TOTAL_AMOUNT - SUM(CMN_BANK_LOAN_PAY.AMOUNT) AS OUTSTANDING
FROM
CMN_BANK_LOAN
LEFT JOIN CMN_BANK_LOAN_PAY
ON CMN_BANK_LOAN.ID = CMN_BANK_LOAN_PAY.LOAN_ID
INNER JOIN CMN_ACCOUNT_MASTER
ON CMN_ACCOUNT_MASTER.ID = CMN_BANK_LOAN.AC_ID
GROUP BY CMN_BANK_LOAN.ID,
CMN_BANK_LOAN.LOAN_DATE,
CMN_BANK_LOAN.REPAY_DATE,
CMN_BANK_LOAN.BY_WHOM,
CMN_BANK_LOAN.TOTAL_AMOUNT,
CMN_ACCOUNT_MASTER.ACCOUNT_NO,
CMN_ACCOUNT_MASTER.BANK_NAME) AS A
WHERE A.OUTSTANDING <> 0
ORDER BY A.LOAN_DATE) AS B

Linq:

from B in (
(from A in (
(from CMN_BANK_LOAN in _appdb.CMN_BANK_LOAN
join CMN_BANK_LOAN_PAY in _appdb.CMN_BANK_LOAN_PAY on new { ID = CMN_BANK_LOAN.ID } equals new { ID = CMN_BANK_LOAN_PAY.LOAN_ID } into CMN_BANK_LOAN_PAY_join
from CMN_BANK_LOAN_PAY in CMN_BANK_LOAN_PAY_join.DefaultIfEmpty()
group new {CMN_BANK_LOAN, CMN_BANK_LOAN.CMN_ACCOUNT_MASTER, CMN_BANK_LOAN_PAY} by new {
CMN_BANK_LOAN.ID,
CMN_BANK_LOAN.LOAN_DATE,
CMN_BANK_LOAN.REPAY_DATE,
CMN_BANK_LOAN.BY_WHOM,
CMN_BANK_LOAN.TOTAL_AMOUNT,
CMN_BANK_LOAN.CMN_ACCOUNT_MASTER.ACCOUNT_NO,
CMN_BANK_LOAN.CMN_ACCOUNT_MASTER.BANK_NAME
} into g
select new {
g.Key.ID,
g.Key.LOAN_DATE,
g.Key.REPAY_DATE,
g.Key.AC_ID,
AC_NO = (g.Key.ACCOUNT_NO + " : " + g.Key.BANK_NAME),
g.Key.BY_WHOM,
g.Key.TOTAL_AMOUNT,
PAID_AMOUNT = (decimal?)g.Sum(p => p.CMN_BANK_LOAN_PAY.AMOUNT),
OUTSTANDING = (decimal?)(g.Key.TOTAL_AMOUNT - g.Sum(p => p.CMN_BANK_LOAN_PAY.AMOUNT))
}))
where
A.OUTSTANDING != 0
orderby
A.LOAN_DATE
select new {
A
}))
select new {
B.A.ID,
B.A.LOAN_DATE,
B.A.REPAY_DATE,
B.A.AC_ID,
B.A.AC_NO,
B.A.BY_WHOM,
B.A.TOTAL_AMOUNT,
B.A.PAID_AMOUNT,
B.A.OUTSTANDING
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.