Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving From LINQpad to a Proper Visual Studio Project?

I'm learning LINQ to SQL in LINQpad and it's been great, but there's a lot of magic happening under the hood that I don't quite understand. I am connecting to an Oracle database using the optional IQ driver that can be downloaded inside of LINQpad. I have my query working and now I need to move it into a new project within Visual Studio.

  1. Is it possible to use IQ within my solution in Visual Studio? I can't seem to find any information about using it outside of LINQpad. I've attempted to use DbLinq's DbMetal tool to generate the proper connection class but something in my schema is choking the tool in a way that it did not for IQ.

  2. Can the generated code for LINQpad be exported in some way? The generated Oracle connection code works perfectly in LINQpad - is there a way to just reuse that generated code?

like image 456
technomalogical Avatar asked Nov 15 '11 17:11

technomalogical


2 Answers

Yes, it's technically possible to use the typed DataContext that LINQPad creates within your own VS solution. You can extract it by running a query such as this:

File.Copy (GetType().BaseType.Assembly.Location, ...

As Tom suggests, you'll also need to copy the supporting files in C:\ProgramData\LINQPad\Drivers\DataContext\4.0\IQDriver. Bear in mind that LINQPad uses the DevArt Oracle dotConnect as the ADO.NET backend for Oracle, for which you'll need to buy a commercial license in order to use in your own projects.

Another issue is that there's no way to customize the typed DataContext and this could prove limiting within the context of writing a VS solution (LINQPad generates the typed DC via Reflection.Emit and so there's no source code to tweak).

If you want to access Oracle databases via LINQ in a VS project, a better option might be buy DevArt's professional edition of dotConnect for Oracle which gives you an entire stack including an integrated VS designer for writing DataContexts (so you won't need IQ). The whole experience is very much like LINQ to SQL, but for Oracle (in fact, they've mimicked the API whereever possible which eliminates the learning curve). DevArt's LINQ translation engine has improved over the years and is now close to IQ's in translation ability (and better in some ways).

like image 77
Joe Albahari Avatar answered Oct 17 '22 12:10

Joe Albahari


Yes, you can use the IQ (IQToolkit & IQToolkit-Oracle Provider) within your projects. You can get the dlls from your LINQPad install (C:\ProgramData\LINQPad\Drivers\DataContext\4.0\IQDriver*).

You will also want to use IQToolkit CodeGen tool to create your Entities and mappings.

like image 25
Tom Brothers Avatar answered Oct 17 '22 12:10

Tom Brothers