LINQ to Teradata

access_time 6 years ago visibility1406 comment 0

In my previous post, I demonstrated how to use ADO.NET to connect to Teradata in your OLTP projects.  In this sample, I am going to implement the same sample using ADO.NET Entity Model, Entity Framework and LINQ.

Connect to Teradata Database via .NET Data Provider


Step 1 Create ADO.NET Entity Data Model

In the wizard, create ‘TDSample.edmx’ through item ‘ADO.NET Entity Data Model’.


Select Generate from Database:


Create a connection to Teradata database:


Remember to set the option ‘Use X Views’ to false and set the Database to the database you are using. I also changed the timeout options as my local VM responds slowly.

The entity connection string looks like:

metadata=res://*/TDSample.csdl|res://*/TDSample.ssdl|res://*/TDSample.msl;provider=Teradata.Client.Provider;provider connection string="connection timeout=90;database=TD_MS_SAMPLE_DB;user id=dbc;data source=;persist security info=True;use x views=False;restrict to default database=True;command timeout=90"

* Change the server and user id/password to yours.

Click next to choose the entity framework version.


And then choose the right tables required.


Click Finish button to close the wizard. In my sample, the model has two tables added.


Step 2 LINQ to Teradata

With the generated entity objects, it will be very straightforward to query from the database.

The sample code looks like:

static void Main(string[] args)


        private static void DisplayEmployeeInfoFromTeraData2()
            var db = new TDSampleContainer();
            var query = from emp in db.Employees.AsQueryable()
                        select new
                            EmployeeID = emp.EmployeeID,
                            EmployeeName = emp.EmployeeName,
                            EmployeeSalutation = emp.Gendar == "M" ? "Dear MR " + emp.EmployeeName :
                                      "Dear MS " + emp.EmployeeName
            foreach (var e in query)
                Console.WriteLine("EmployeeID = {0}", e.EmployeeID);
                Console.WriteLine("EmployeeName = {0}", e.EmployeeName);
                Console.WriteLine("Employee Salutation = {0}", e.EmployeeSalutation);

            Console.WriteLine("{0} Records", query.Count());

The result



With .NET Data Provider for Teradata, you can easily operate on the database with Linq. If you want to learn more about LINQ, please visit the following link:

info Last modified by Raymond at 5 days ago copyright This page is subject to Site terms.
Like this article?
Share on

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

Want to publish your article on Kontext?

Learn more

Kontext Column

Created for everyone to publish data, programming and cloud related articles.
Follow three steps to create your columns.

Learn more arrow_forward

More from Kontext

local_offer .NET local_offer C# local_offer dotnetcore local_offer Linq

visibility 15
thumb_up 0
access_time 7 days ago

Language-Integrated Query (LINQ) is a set of technologies based on the integration of query capabilities directly into the C# or VB language in .NET. It allows intuitive query against SQL databases, XML, object list, etc.  This article shows how to return a top N records randomly.  The ...

About column

About C# Programming Language: features, syntax, usages and so on.

rss_feed Subscribe RSS