linqpad

How to export data from LinqPAD as JSON?

依然范特西╮ 提交于 2019-12-03 10:56:14
I want to create a JSON file for use as part of a simple web prototyping exercise. LinqPAD is perfect for accessing the data from my DB in just the shape I need, however I cannot get it out as JSON very easily. I don't really care what the schema is, because I can adapt my JavaScript to work with whatever is returned. Is this possible? A more fluent solution is to add the following methods to the "My Extensions" File in Linqpad: public static String DumpJson<T>(this T obj) { return obj .ToJson() .Dump(); } public static String ToJson<T>(this T obj) { return new System.Web.Script.Serialization

Different SQL produced from Where(l => l.Side == 'A') vs Where(l => l.Side.Equals('A')

给你一囗甜甜゛ 提交于 2019-12-03 10:46:27
I've been experimenting with queries in LinqPad. We have a table Lot with a column Side char(1) . When I write a linq to sql query Lots.Where(l => l.Side == 'A') , it produces the following SQL -- Region Parameters DECLARE @p0 Int = 65 -- EndRegion SELECT ..., [t0].[Side], ... FROM [Lot] AS [t0] WHERE UNICODE([t0].[Side]) = @p0 However, using Lots.Where(l => l.Side.Equals('A')) , it produces -- Region Parameters DECLARE @p0 Char(1) = 'A' -- EndRegion SELECT ..., [t0].[Side], ... FROM [Lot] AS [t0] WHERE [t0].[Side] = @p0 It would appear upon (albeit naïve) inspection, that the latter would be

How to add a reference to an assembly in LINQPad to access custom types?

不打扰是莪最后的温柔 提交于 2019-12-03 09:19:05
Is there a posibility to add a reference to an assembly in LINQPad? I have some types in my assembly and I would like to use them in my LINQPad queries. Just press F4 . This will pop up the Add Reference dialog. You can also use the menu option to access the popup window to add references. Notice the >> arrows in menu bar. Click on it. Go to Query menu. Find References and Properties . Click on it. Following is example image from LINQPad 5: thedanotto I had to do fn and F4 at the same time. 来源: https://stackoverflow.com/questions/11432642/how-to-add-a-reference-to-an-assembly-in-linqpad-to

Steps for a beginner to run very basic linq to sql query using Linqpad

烂漫一生 提交于 2019-12-03 09:00:52
问题 Trying to learn Linq using LinqPad and getting frustated with how to start on it. Let's say I want to write a C# Expression and a C# statment where I have a table in SQL server named Products and I want to pull all rows where price is greater then 50. How would yo write it? 回答1: Let's say I want to write a C# Expression and a C# statment where I have a table in SQL server named Products and I want to pull all rows where price is greater then 50. How would yo write it? LINQPad builds the typed

How to submit changes in LinqPad

天涯浪子 提交于 2019-12-03 08:11:04
问题 I have a problem with committing changes in LinqPad. I am using Oracle database over IQ driver in LinqPad. I can retrieve data but I don't know how to submit changes to database. I retrieve data from database: var items = Asyncqueue.Where(x => ids.Any(y=> y == x.Asyncqueueid)); // then I have to fix data I have tried to set submit action like this: Asyncqueue.SetSubmitAction(items, SubmitAction.Update); 回答1: Change Language in LINQPad to "C# Program" and use the following code void Main() {

How does Visual Studio's debugger/interactive window dump the properties of COM Objects in .NET?

不羁岁月 提交于 2019-12-03 06:39:30
In this related question , I noted that Visual Studio's debugger is able to enumerate the properties of System.__ComObject references, which is "a hidden type used when the wrapper type is ambiguous" -- e.g., the type of object you get when you obtain it from another COM object and don't instantiate it yourself: Additionally, if you simply write a COM object's identifier into the Immediate Window, its properties and values are similarly dumped: Note that this is separate from VS2010's " Dynamic View ", which I believe uses IDispatch and COM reflection to enumerate the properties of COM objects

invalid cast exception on int to double

笑着哭i 提交于 2019-12-03 05:31:11
Maybe I'm crazy, but I thought this was a valid cast: (new int[]{1,2,3,4,5}).Cast<double>() Why is LinqPad throwing a InvalidCastException: Specified cast is not valid. ? C# allows a conversion from int directly to double , but not from int to object to double . int i = 1; object o = i; double d1 = (double)i; // okay double d2 = (double)o; // error The Enumerable.Cast extension method behaves like the latter. It does not convert values to a different type, it asserts that values are already of the expected type and throws an exception if they aren't. You could try (new int[]{1,2,3,4,5}).Select

Can I have an incrementing count variable in LINQ?

最后都变了- 提交于 2019-12-03 05:14:00
I want to do something like this: from a in stuff let counter = 0 select new { count = counter++, a.Name }; But I get a error telling me that counter is read only. Is there a way to do something similar to this, without declaring a variable outside of the query? Basically, I just want to show a count/index column in LINQPad (which is awesome, BTW), which means I can't declare counter ahead of time. Rather than using side-effects, use the overload of Select which takes an index: stuff.Select((value, index) => new { index, value.Name }); You could do it using side-effects, but not in the way you

How does LINQPad reference other classes, e.g. Books in the LINQ in Action samples

China☆狼群 提交于 2019-12-03 03:49:32
问题 I'm using LINQPad to create LINQ queries in an application I'm bulding. I noticed that in the downloaded LINQ in Action samples, e.g. example 4.04, intellisense shows a class "Books" but I don't see any references or " using " statements in the LINQPad tool, here is the sample: List<Book> books = new List<Book>() { new Book { Title="LINQ in Action" }, new Book { Title="LINQ for Fun" }, new Book { Title="Extreme LINQ" } }; var titles = books .Where(book => book.Title.Contains("Action"))

LINQPad - Connection String to my Oracle DB

旧街凉风 提交于 2019-12-03 03:47:26
I just started using LINQPad and all works great when connecting to my SQL Server DB, but now I'm trying to set up a second connection to my Oracle DB and I'm getting stuck as to how to do it. I downloaded the IQ driver (v 2.0.8.0 - Latest) and when I go to add a new connection, I select Oracle as my DB Provider and don't know how to do the rest based upon my usual connection string looking as follows: Data Source=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = [IP Address])(PORT = [Port]))(CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = [Service Name])));User Id=[name];Password=[password]