1
  1. Is LINQ the best solution for data to object automatic mapping using .NET? Can anyone suggest me some other solution the create automatically the database table and stored procedure mapping ?

  2. Is it possible convert LINQ( or other solution) result into Dataset or Datatable automatically ?

Brian Webster
  • 30,033
  • 48
  • 152
  • 225
arthur86
  • 531
  • 1
  • 3
  • 20

6 Answers6

6

LINQ is not an ORM. It's just a language extension that provides SQL-query-like syntax and queryable types that "integrate" query expressions to your programs. It does not map objects to the database whatsoever.

That said:

  1. LINQ to SQL is an ORM that uses LINQ. Again, as you see, LINQ itself isn't an ORM, but can be used in an ORM framework. But as mentioned by AHM, also take a look at Entity Framework.

    A well-known open source .NET ORM solution is NHibernate which is really a .NET port of Hibernate for Java.

  2. MSDN has articles on LINQ to DataSet, but this isn't related to object-relational mapping.

Community
  • 1
  • 1
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
  • 3
    I don't think there is any point in starting to use Linq-to-SQL nowadays. While Microsoft continues to say that they still support it, and that it isn't dead, it seems to me that the Entityframework is what they really are focusing on. – AHM May 29 '11 at 23:03
  • 1
    Reason: It is faster to do simple to medium-complexity programs in LINQ to SQL. – Brian Webster May 29 '11 at 23:08
  • @hamlin11, as of 2008 the recommended approach was to use EF, not Linq-to-SQL. It's really ridiculous to start a new project with Linq-to-SQL in 2011. http://blogs.msdn.com/b/adonet/archive/2008/10/29/update-on-linq-to-sql-and-linq-to-entities-roadmap.aspx – Samuel Neff May 30 '11 at 01:50
  • 1
    Arriving at that conclusion based upon that blog post is a serious reach. http://stackoverflow.com/questions/252683/is-linq-to-sql-dead-or-alive Furthermore, it is a fact that you can, in .NET 4.0, develop a majority of small to medium-complexity applications faster and more simply with LINQ to SQL. "Some bloggers said LINQ is dead" and "MS said they're not going to add new features to it" are not very good arguments, in my opinion, in favor of not using a technology. Maybe I'm just being pragmatic – Brian Webster May 30 '11 at 02:41
  • I'm sorry about my mistake. I use .net class (Linq2SQL) that let me to map db tables into objects. That's because i said Linq is ORM. Thanx for your responce. I took a look to Entity Framework, but i found some limitation for automatic mapping of Stored Procedure. In particular those with multiple-set result. Any suggestion ?? – arthur86 May 30 '11 at 07:39
1

Populating Datasets or Datatables with LINQ

LINQ to Dataset - Getting Started

LINQ to Dataset - Programming Guide

LINQ Query to Datatable Example

var query1 = from i in items
             where i.Price > 9.99
             orderby i.Price
             select i;

// load into new DataTable
DataTable table1 = query1.CopyToDataTable();

LINQ to SQL Alternatives

Brian Webster
  • 30,033
  • 48
  • 152
  • 225
1

For a new application you should probably use either Entity Framework or NHibernate. Both are mature ORM solutions and both support LINQ for language integrated queries.

LINQ-to-SQL is an option, but it's pretty much deprecated in favor of Entity Framework. You shouldn't use it for a new application.

DataSets are pretty much the opposite of ORM. They're creating an in-memory representation of your relational data in an object whose sole purpose is to represent that data. They work for very quick results or when your data is truly dynamic, but generally are far inferior to any true ORM solution.

Samuel Neff
  • 73,278
  • 17
  • 138
  • 182
1

Arthur, your question is not really answerable in any meaningfull way as it is written.

Linq stands for Language Integrated Query, and by itself is not an ORM (Object relational Mapping) framework. There are however ORM's that do make heavy use of Linq, Microsoft have 2 flavours, Linq to SQL and Linq to Entities Framework, there are also 3rd party ORM's that also make use of Linq..NHibernate for example.

Then your follow up question of convert Linq to Dataset / Datatable, while not actually making any sense also implies that you would rather be working with or binding to database middleware components, this would make using an ORM pretty redundant in most cases.

What an ORM does is allows you to map your domain model to a data model, so that in your application you never need to think in terms of your data model and structures you just think in terms of your domain objects....your code would look like this...

IEnumerable<Customer> Custs = someRepository.Customers();
foreach(Customer c in Custs)
{
  // Do something with the custs.
}

Instead of...

var cmd = connection.CreateCommand();
cmd.CommandText = "Select * from customers";
using(var reader = cmd.ExecuteReader())
{
  // etc etc
}

Maybe if you could post a little more of what you are trying to achieve, we could give you some better advice.

Tim Jarvis
  • 18,465
  • 9
  • 55
  • 92
  • I'm working to improve old web application. I have old data layer that use some SQL query. I would remove this layer with a layer generated automatically by modern ORM. Then i would re-write Business Logic to became faster the application. But i want re use the BLL interface (Dataset). – arthur86 May 30 '11 at 06:51
0

1) LINQ is a query language it is not an ORM. Just see the wiki page for available ORMs. It is too hard to get the one that suits you best without knowing where you will use it

2) Suggested by hamlin11 + Castle Active Record looks like a DataTable. But I wouldn't mix DataSet and DataTable with ORM as this technologies use different memory and data update strategies

oleksii
  • 35,458
  • 16
  • 93
  • 163
  • I' sorry for my confusion. I use .net class that let me to map db tables into objects. That's because i said Linq2sql it's ORM. Thanx for your responce. – arthur86 May 30 '11 at 07:05
0

While LinqToSQL is not technically and ORM, it's a perfectly good substitute if you want basic functionality like direct table to object mapping.

The other MS tool is Entity Framework, which supports, Model first, Database first and Code first models.

Entity Framework is more advanced then LingToSQL as it allows you to split and combine tables to different entites and a lot more advanced options. There are a lot of good video's at http://www.asp.net or at Pluralsight

I'm not sure if Linq can easily be converted to datasets and datatables but there isn't really any need to, it's just changing from one data object type to another.

Simon Holman
  • 150
  • 6