NHibernate vs LINQ to SQL

LINQ to SQL forces you to use the table-per-class pattern. The benefits of using this pattern are that it’s quick and easy to implement and it takes very little effort to get your domain running based on an existing database structure. For simple applications, this is perfectly acceptable (and oftentimes even preferable), but for more … Read more

Linq where column == (null reference) not the same as column == null

Change where (s.crmc_Retail_Trade_Id == tradeId) to where (s.crmc_Retail_Trade_Id == tradeId || (tradeId == null && s.crmc_Retail_Trade_Id == null)) Edit – based on this post by Brant Lamborn, it looks like the following would do what you want: where (object.Equals(s.crmc_Retail_Trade_Id, tradeId)) The Null Semantics (LINQ to SQL) MSDN page links to some interesting info: LINQ to … Read more

LINQ to SQL Where Clause Optional Criteria

You can code your original query: var query = from tags in db.TagsHeaders where tags.CST.Equals(this.SelectedCust.CustCode.ToUpper()) && Utility.GetDate(DateTime.Parse(this.txtOrderDateFrom.Text)) <= tags.ORDDTE && Utility.GetDate(DateTime.Parse(this.txtOrderDateTo.Text)) >= tags.ORDDTE select tags; And then based on a condition, add additional where constraints. if(condition) query = query.Where(i => i.PONumber == “ABC”); I am not sure how to code this with the query syntax … Read more

Building Dynamic LINQ Queries based on Combobox Value

Assuming: public class Person { public string LastName { get; set; } } IQueryable<Person> collection; your query: var query = from p in collection where p.LastName == textBox.Text select p; means the same as: var query = collection.Where(p => p.LastName == textBox.Text); which the compiler translates from an extension method to: var query = Queryable.Where(collection, … Read more