100 likes | 196 Views
Introduction to LinqToSQL AWW YEA FOO!. Jonas Avellana TYCO Thermal Controls. Who is Jonas?. Work for. Let’s Start. What is LINQ? Short for Language-Integrated Query An “SQL”-like syntax to query in-memory collections Frikken awesome! Why LINQ? DEMO. What is LinqToSQL ?
E N D
Introduction to LinqToSQLAWW YEA FOO! Jonas Avellana TYCO Thermal Controls
Who is Jonas? • Work for
Let’s Start • What is LINQ? • Short for Language-Integrated Query • An “SQL”-like syntax to query in-memory collections • Frikken awesome! • Why LINQ? • DEMO
What is LinqToSQL? • Another OR\M • Queries are written in LINQ • Instead of in-memory collection queries, we go to a SQL Server database • One-to-one implementation
Other ORM’s • NHibernate • Castle ActiveRecord (Runs under NHibernate) • Linq To Entities (Microsoft’s “NHibernate”) • Many more!
Scenario • Photo Album • Has many photos • Has many sets • A set can have many photos • A set has details • A.K.A. Jonas’ Ghetto Flickr
Pros • Very easy to write LINQ • No more mapping files (Photo.hbm.xml) • Can be used with existing SQL Server databases • Can call SQL & Stored Procs • Less string keys to use that may cause errors (gateway.CreateParameter(“itemId”, item.ItemId)) • Lazy Loading!
Cons • SQL Server only. • Could be slower than other ORM or hand rolled data access objects. • Could be a pain to maintain if you use the LinqToSql designer (drag + drop) if you keep on refactoring your database • May cause multiple database calls • Can be avoided with DataLoadOptionsor with a proper IQueryable<T> query