Connect to SQL DB via Custom Schema? (code generated from template files - VS 2010)
I've recently discovered LINQPad and LOVE it. Up to this point, the connection I've been using is a direct connection to our SQL Server DB. That works great; however, because we use a custom schema, I can't just paste a query from Visual Studio directly into LINQPad and have it work.
Hopefully, what I'm describing below makes sense. If not, please let me know what needs clarification.
In Visual Studio, we use a custom schema, code generator with templates, and IQToolkit (I didn't set this up so I, admittedly, have limited knowledge of how it all works, but if more information is needed regarding this setup, I can ask around here at work...I just need to know what questions to ask.)
For example, here's a (very simple) query I'd write in VS...
from x in HrHrcode
select x.LongDesc
In order to get it to work in LINQPad, I have to change it like so...
from x in Hr_hrcode
select x.Long_desc
...because, as mentioned, I'm connecting directly to the DB in LINQPad and Hr_hrcode and Long_desc are the actual table and column name in the DB (notice the underscores and differences in case...this particular DB is case sensitive.)
I know LINQPad has the option of using typed data contexts from an assembly when creating a new connection, but I can't seem to get it to work because 1) I'm not sure which LINQPad Driver option I should be using (LINQ to SQL, Entity Framework, or Entity Framework DbContext POCO (4.1/4.2/4.3)) and, 2) when choosing one of those options, I'm not sure which assembly I should be using (I've tried all Driver 3 options with various DLLs from our project that I thought would contain the custom entity info, but I guess I haven't hit upon the right combination of Driver option and DLL.)
Is it possible to have LINQPad recognize our custom schema with this setup?
Hopefully, what I'm describing below makes sense. If not, please let me know what needs clarification.
In Visual Studio, we use a custom schema, code generator with templates, and IQToolkit (I didn't set this up so I, admittedly, have limited knowledge of how it all works, but if more information is needed regarding this setup, I can ask around here at work...I just need to know what questions to ask.)
For example, here's a (very simple) query I'd write in VS...
from x in HrHrcode
select x.LongDesc
In order to get it to work in LINQPad, I have to change it like so...
from x in Hr_hrcode
select x.Long_desc
...because, as mentioned, I'm connecting directly to the DB in LINQPad and Hr_hrcode and Long_desc are the actual table and column name in the DB (notice the underscores and differences in case...this particular DB is case sensitive.)
I know LINQPad has the option of using typed data contexts from an assembly when creating a new connection, but I can't seem to get it to work because 1) I'm not sure which LINQPad Driver option I should be using (LINQ to SQL, Entity Framework, or Entity Framework DbContext POCO (4.1/4.2/4.3)) and, 2) when choosing one of those options, I'm not sure which assembly I should be using (I've tried all Driver 3 options with various DLLs from our project that I thought would contain the custom entity info, but I guess I haven't hit upon the right combination of Driver option and DLL.)
Is it possible to have LINQPad recognize our custom schema with this setup?
Comments
The workaround is to add a reference to your assemblies in the query properties dialog instead of adding a connection. Then set the query language to C# statements and do this: Once you've added the references and namespaces, you can save these to a snippet if you have LINQPad Premium edition. Press 'Save as Snippet', and type something like iq. Then to add those references/namespaces to another query, simply type iq TAB.
To avoid LINQPad walking association properties, use Results to Grid mode, or call Dump with a number:
query.Dump(2);
or
query.Dump(true) // Force dump to grids.
I tried what you recommended... And it's giving me a error on the "var" keyword on this line... So I tried this... And it lists all of the table names in the schema, but next to each one of them it says If I expand the NullReferenceException next to one of the tables, I get the output and stack trace below.
I painstakingly went through and added all of the references from our project (85 of them) and the namespaces I thought I needed, but I get the same results.
I know that without you having specific knowledge about our project you may not be able to help me any further, but do you have any idea what I might still be missing here?
Output and Stack Trace fromNullReferenceException next to one of the tables...