C# 3.0 in a Nutshell
C# 3.0 in a Nutshell, Third Edition A Desktop Quick Reference By Joseph Albahari, Ben Albahari
September 2007
Pages: 858


Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
Sql Server Built-in Functions, How do I access them?
MaslowJax
post Jul 3 2009, 04:21 AM
Post #1


New Member
*

Group: Members
Posts: 7
Joined: 1-July 09
From: Jacksonville,FL
Member No.: 18,958



Is there a namespace for SQL server built in functions like getdate()? Is there a way to access these functions? Intellisense doesn't seem to pick up a way to do either.

What about sys.schemas?

information_schema.columns?

If any of these require a special namespace to access, will the import namespace feature work?

I'd really like to be able to have a query ready that dumps the column names, possibly types, lengths, not null information to an output window so that I can create business objects based on the table definition.
Go to the top of the page
 
+Quote Post
JoeAlbahari
post Jul 6 2009, 05:24 AM
Post #2


Advanced Member
******

Group: Members
Posts: 203
Joined: 15-February 08
From: Perth, Australia
Member No.: 90



Hi there

There's no way to do this at present. The only way to access a function like getdate() is to map it to a scalar function on SQL Server.

> What about sys.schemas?

You have to use SQL for this. If you want to bring it into C#-land, change the query type to Program and execute the following:

CODE
void Main()
{
   ExecuteQuery<SysSchema>
    ("select * from sys.schemas").Dump();
}

class SysSchema
{
   public string Name;
   public int Schema_ID;
  public int Principal_ID;
}


Joe

This post has been edited by JoeAlbahari: Jul 6 2009, 05:24 AM
Go to the top of the page
 
+Quote Post
MaslowJax
post Jul 24 2009, 05:53 AM
Post #3


New Member
*

Group: Members
Posts: 7
Joined: 1-July 09
From: Jacksonville,FL
Member No.: 18,958



Is this a limitiation of linq or linqpad?
Go to the top of the page
 
+Quote Post
JoeAlbahari
post Jul 24 2009, 07:14 PM
Post #4


Advanced Member
******

Group: Members
Posts: 203
Joined: 15-February 08
From: Perth, Australia
Member No.: 90



I think it's possible to do these things in LINQ to SQL with manually-created methods and entities.

Try the following:

CODE
[Function (Name = "GetDate", IsComposable = true)]
public DateTime GetDate ()
{
  return (DateTime)(this.ExecuteMethodCall (this, ((MethodInfo)(MethodInfo.GetCurrentMethod ()))).ReturnValue);
}


Joe

Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version Time is now: 7th November 2009 - 01:26 PM