Posted By: vesuvius | Dec 6th, 2007 @ 1:36 AM
page 1 of 1
Comments: 20 | Views: 2872
vesuvius
vesuvius
Das Glasperlenspiel
Just found a really really useful feature on the VB site that alllows one to easily create excel docs from SQL via linq. Looking at the following diagram



I very much doubt you can linq to excel via sql unless you use VB. If not I'll have to use VB.

PS some VB language intricacies (press 'space' instead of 'return ' when coding. Place a '_' at the end of a linq query line - I'd rather not have to go through this strangeness)
i hope not, in VB while it looks like nice, its crazy, i don't like it, yes of course its better that in C# but there must be a better way... you can't just put a language in other language like that
evildictaitor
evildictaitor
if( !succeed( try() ) ) { while(true) try(); }
No. This is a VB-only feature (and is only available in VB in and after VS2008 also).
Sven Groot
Sven Groot
My name has 9 letters. Coincidence? I think not...
vesuvius wrote:
Sorry, I wasn't clear, does anyone know a workaround to use the above via C#

You need to use XDocument and the related classes. This post on my blog gives a short XML literals example and the C# equivalent at the bottom.
stevo_
stevo_
Human after all
Interesting that the if ternary is stated as a VB feature, I know this is a break down of the new features, but it doesn't really highlight that C# has been slapping VBs face around for years with its own..
Sven Groot
Sven Groot
My name has 9 letters. Coincidence? I think not...
stevo_ wrote:
Interesting that the if ternary is stated as a VB feature, I know this is a break down of the new features, but it doesn't really highlight that C# has been slapping VBs face around for years with its own..

Yeah, I noticed that too. Same is true for Nullable syntax, C# had that in 2005 already.
littleguru
littleguru
<3 Seattle
Btw., just as a side note, the VB.NET XML literals are translated to XDocument, XElement calls when the VB.NET compiler compiles them.
littleguru
littleguru
<3 Seattle
vesuvius wrote:

littleguru wrote: Btw., just as a side note, the VB.NET XML literals are translated to XDocument, XElement calls when the VB.NET compiler compiles them.


So XML literals are no more than 'syntactic sugar'. VB allows users to paste XML, that is then accessed the same way C# does using the same classes anyway?


sugar, compiler magic, call it as you want Smiley
 
Compile a method that uses xml literals and open it in reflector. you'll see that they only got converted to XElement, XDocument caslls.
Sven Groot
Sven Groot
My name has 9 letters. Coincidence? I think not...
vesuvius wrote:
It did not seem so strange becuase I was still getting used to the fact that pressing enter/return after intellisense in VB ignores the intellisense and you need to press space.

Tab also works, as does any character that would come after the identifier (like '(' or a dot or an operator).

vesuvius wrote:
is this the derivation of the 'XML literal' nomenclarure

No. If you have something like "Hello world" in your code, it's called a string literal. XML literals are similar, except that they define XML instead of plain text strings.
Ion Todirel wrote:
i hope not, in VB while it looks like nice, its crazy, i don't like it, yes of course its better that in C# but there must be a better way... you can't just put a language in other language like that


I always find these types of comments silly (please don't take offense, as none was meant).  Many languages allow you to create DSLs and use them directly within your code.  People using those languages find this to be a good thing! You can already create DSLs in C#, you're just highly constrained with the syntax you can use.  The XDocument examples given as the C# equivalent ARE such a DSL.  Very close to "XML literals", but with some "pesky" syntax differences.  LINQ also has a DSL with "pesky" syntax, but C# included the sugar to allow you to write the queries in a form that loses these "pesky" syntactic differences.  Do you have a problem with LINQ embedding a different language within C#?  Why shouldn't C# also provide the syntactic sugar to allow XML literals?  Better yet, why shouldn't C# allow us to create our own DSLs with greater syntactic freedom?
wkempf wrote:

Ion Todirel wrote:i hope not, in VB while it looks like nice, its crazy, i don't like it, yes of course its better that in C# but there must be a better way... you can't just put a language in other language like that


I always find these types of comments silly (please don't take offense, as none was meant).  Many languages allow you to create DSLs and use them directly within your code.
i'm not a fan of object-oriented rendering either, but there must be a better way, just look at LINQ, the problem is not with xml alone, what thy did is fine but it works only for xml, i don't know i just don't like it

Crazy????

 

I love it!!!

 

That's the nicest thing that ever happened to me!

W3bbo
W3bbo
The Master of Baiters

Hmm, thread necromancy.

 

Unless I'm mistaken, I think that graph in the OP is wrong, C# had has the ternary operator since the beginning and nullable syntax since 2.0.

CannotResolveSymbol
CannotResolveSymbol
{insert caption here}

I think it's listing features that were new to the languages at the time.

 

staceyw
staceyw
Before C# there was darkness...

As a side note to not intermix issues, this has nothing to do with sql.

In c#, you could do the same kind of thing like below.  VB is essencially doing the same thing behind the covers.  With some new DSL language/library stuff they are working on (shown here on c9), we may be able to do the same thing in c# without adding it to the language.

 

// Create memory list.
Employees emp1 = new Employees() {FirstName="Bill", LastName="Gates" };
Employees emp2 = new Employees() {FirstName="Don", LastName="Box" };
List<Employees> list = new List<Employees>() { emp1, emp2 };

// Create xml from a data source.

XElement xml = new XElement("employees",
        from emp in list
        select new XElement("employee",
            new XElement("firstName", emp.FirstName),
            new XElement("lastName", emp.LastName))
    );
Console.WriteLine(xml.ToString());

 

Output:

 

 

<employees>

<employee>

<firstName>Bill</firstName>

<lastName>Gates</lastName>

</employee>

<employee>

<firstName>Don</firstName>

<lastName>Box</lastName>

</employee>

</employees>

 

btw - how come the insert code gives strange 1 line results?  I had to just paste text.

stevo_
stevo_
Human after all

Why would you have a model called 'Employees' when it clearly represents a Person / Employee Tongue Out

page 1 of 1
Comments: 20 | Views: 2872
Microsoft Communities