background preloader


Facebook Twitter

Linq - Convert Dataset to IQueryable<T> or IEnumerable<T> Current community your communities Sign up or log in to customize your list. more stack exchange communities Stack Exchange sign up log in tour help careers 2.0 Stack Overflow Ask Question Take the 2-minute tour × Stack Overflow is a question and answer site for professional and enthusiast programmers.

linq - Convert Dataset to IQueryable<T> or IEnumerable<T>

Convert Dataset to IQueryable<T> or IEnumerable<T> 3 Answers active oldest votes Your Answer Sign up or log in Sign up using Google Sign up using Facebook Sign up using Stack Exchange Post as a guest discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Linked. C# - Linq to sql convert IQueryable to Dataset. If you create a DataTable from schema so it matches your LINQ to Sql, I have an extension method that takes the IQueryable and fills the DataTable: public static DataTable AsDataTable(this IQueryable value, DataTable table){ var reader = value.GetEnumerator(); while (reader.MoveNext()) { var record = (Customer)reader.Current; table.Rows.Add(record.CustomerID, record.City); } return table;} Note that the cast to Customer is my TEntity: [Table(Name = "Customers")]public class Customer{ [Column(IsPrimaryKey = true)] public string CustomerID; [Column] public string City;} There are other options that use reflection to build your DataTable from the Customer class.

c# - Linq to sql convert IQueryable to Dataset

Given the performance hit from reflection, I chose to use the following method to build my table: Putting all that together, I was able to push the results into my DataGridView: dgridRO.DataSource = new DataView(rows.AsDataTable(dmap.GetSchema("CustomerID", "City"))); LINQ to SQL Paging using GridView in C# and ASP.NET 3.5. This tutorial will show you how we can extend the LINQ to SQL Class and create methods that will allow us to page data from a SQL database.

LINQ to SQL Paging using GridView in C# and ASP.NET 3.5

C# version. Using LINQ to SQL, we can make use of the built-in methods to page the database data a lot easier than with using SQL alone. LINQ to SQL can make it extremely easy for us to create pages from our data source using these two methods: - Skip() — Allows us to skip a certain number of records; - Take() — Allows us to select a certain number of records. In this tutorial, we will use a SQL database and extend the LINQ to SQL Class that Visual Studio creates to represent our database by allowing the user to page the data displayed in a GridView control. We will start by creating our database.

Converting anonymous types to any type. Introduction This article describes how to handle conversions from an anonymous type to a specific type by using .NET 3.5 extensions. It is especially helpful when using LINQ to SQL to retrieve data in the form of lists and/or arrays. Problem With Microsoft LINQ to SQL, you enjoy the ability of using a strong programming language and at the same time having control over your data. Data objects are represented by classes automatically created when you link your data structure to your Visual Studio project via DBML files. Instead of dividing your attention between SQL and programming, you can now write data retrieving procedures within your Visual Studio programming environment.

SQL Server 2008 Connection String Samples. 101 LINQ Samples. LINQ to SQL - Detach Entities. Download source - 220.6 KB Introduction How do I use disconnected entities with LINQ to SQL?

LINQ to SQL - Detach Entities

Every developer that has used LINQ to SQL has asked this question in dismay. Where is the detach? How do I use these entities with services, JSON, encapsulation, and multiple data contexts? Getting Setup We will use the Petshop database to demonstrate detaching LINQ to SQL entities. Detaching from a DataContext To ensure that an entity is completely detached, we need to examine each child entity, child entity list and every property that is delay or lazy loaded. The Product entity contains all the different scenarios we have come across when detaching entities. To detach the Product entity, the first thing we need to do is create a Product partial class.

Partial class Product { public override void Detach() { if (null == PropertyChanging) return; PropertyChanging = null; PropertyChanged = null; } } First, a check is made to verify that the entity is attached to a context. LINQ to SQL: .NET Language-Integrated Query for Relational Data. MSDN Library Articles and Overviews.

LINQ to SQL: .NET Language-Integrated Query for Relational Data

LINQ To SQL and the Web.Config ConnectionString Value. I just got had by an odd behavior in the LINQ to SQL model designer when working with a LINQ to SQL Model in a separate class library project.

LINQ To SQL and the Web.Config ConnectionString Value

I use LINQ to SQL in a business layer which always lives in a separate assembly and so the model does not live in the same project as the Web (or other) application I'm working on. When the model is created the DataContext has options on how the Connection is handled when you create your DataContext without specifying any parameters in the constructor - ie. you're instantiating the DataContext without a connection string or connection object: TimeTrakkerContext context = new TimeTrakkerContext(); When you do this the settings are read from the configuration settings or the default connection string if no settings are available. You can see these settings in the DataContext properties under Connection: You can specify a default connection string, and whether you like to use Application Settings to read the value from your config file.

OnCreated(); Simple GridView Binding using LINQ to SQL. Download source - 285.21 KB Introduction.

Simple GridView Binding using LINQ to SQL