Friday, 6 September 2013

running sql scripts inside visual studio 2012 express edition [Topic: C# interpreted queries]

running sql scripts inside visual studio 2012 express edition [Topic: C#
interpreted queries]

I am trying to run a script that contains the following code:
create table Customer
(
ID int not null primary key,
Name varchar(30)
)
insert Customer values (1, 'Tom')
insert Customer values (2, 'Dick')
insert Customer values (3, 'Harry')
insert Customer values (4, 'Mary')
insert Customer values (5, 'Jay')
And integrate it into this C# code
using System;
using System.Linq;
using System.Data.Linq; // in System.Data.Linq.dll
using System.Data.Linq.Mapping;
[Table] public class Customer
{
[Column(IsPrimaryKey=true)] public int ID;
[Column] public string Name;
}
class Test
{
static void Main()
{
DataContext dataContext = new DataContext ("connection string");
Table<Customer> customers = dataContext.GetTable <Customer>();
IQueryable<string> query = from c in customers
where c.Name.Contains ("a")
orderby c.Name.Length
select c.Name.ToUpper();
foreach (string name in query) Console.WriteLine (name);
}
}
So far i only managed to add reference to the System.Data.Linq dll.
I tried googling but i found no answers. This was found in the C# in a
nutshell book, it provided no details about this topic in this book on how
to run it on visual studio 2012 express. (sql file alongside the C# file).

No comments:

Post a Comment