tags:

views:

117

answers:

4

I am using Linq-to-SQL for my projects but i heard about the T4 Template Code generator? Whether T4 Template is better then Linq-To-SQL Data Context?

+2  A: 

You are mixing two things. LINQ to SQL is an O/RM tool, just like NHibernate, Entity Framework, LLBLGen, and others. T4 is a code generator tool. They're not mutually exclusive.

There are T4 templates for LINQ to SQL that allow you to generate your LINQ to SQL entities and DataContext in a different way than the LINQ to SQL code generator would do. Using LINQ to SQL without a DataContext however, is impossible. When you're not using the DataContext, you're not using LINQ to SQL.

Using T4 templates to generate entities and DataContexthowever, can be beneficial. You will have look at the benefits of a particular template and decide whether this is useful to you, or not. For instance the L2ST4 template project on codeplex closely resembles the code that L2S would generate itself, but allows you to alter the template for your own needs.

Steven
A: 

T4 is a text generation system. Writing your data access using it is probably possible, but not recommended. It can't really be considered better or worse that the L2S Data Context because they don't really share a purpose.

I'd suggest that if L2S is limiting you then you need to consider alternate ORMs. There are a number of alternatives. Have a look at NHibernate, Entity Framework or LLBLGen Pro.

AbstractCode
A: 

It's not a "Linq-to-SQL" or "T4" question, really - those are totally different things.

T4 generates code or any kind of text file, really. It's a code-generation technology.

Linq-to-SQL is an ORM - object-relational mapper - to map SQL Server tables to .NET domain objects - totally different ballgame.

As a matter of fact, there's even a set of T4 templates to generate the Linq-to-SQL entity and data context classes - check it out on Codeplex - excellent stuff!

marc_s
+2  A: 

If you like LINQ to SQL, then I strongly suggest that you take a look at PLINQO. PLINQO is an open source (template based, like T4) ORM that not only generates LINQ to SQL entities, but also adds many fixes and enhancements to the framework as well.

Yes, PLINQO requires the CodeSmith Generator, but there is a PLINQO promotion where all you have to do blog or tweet about PLINQO and you can get a copy of CodeSmith for FREE!

Check it out at http://www.plinqo.com

Enjoy! -Tom DuPont (Member of the PLINQO development team)

tdupont