• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1042
  • Last Modified:

Convert T-SQL to Linq

Hello, could someone convert this to Linq2Sql please?

SELECT *
FROM            Customers
WHERE  (FirstName LIKE @FirstName OR @FirstName IS NULL OR @FirstName = '')
  AND  (LastName LIKE @LastName OR @Lastname IS NULL or @LastName = '')
  AND  (PostCode LIKE @PostCode OR @PostCode IS NULL or @PostCode = '')
  AND  (EmailAddress LIKE @EmailAddress OR @EmailAddress IS NULL OR @EmailAddress = '')
  AND  (ContactTel LIKE @ContactTel OR @ContactTel IS NULL OR @ContactTel = '')

Thanks!
0
badpilot
Asked:
badpilot
2 Solutions
 
dj_alikCommented:
C# like this:
var result = from customer in  Customers
where customer.FirstName.StartWith(youpatameter...) AND .............  
select customer
0
 
jeebukarthikeyanCommented:
hi ,

try this way

var cust  = from objCustomer in customer 
where (objCustomer.FirstName.Contains("Mark") && objCustomer.FirstName != null)
&& (objCustomer.LastName .Contains("Anthony") && objCustomer.LastName  != null)
&& (objCustomer.PostCode .Contains("12345k") && objCustomer.PostCode  != null)
select objCustomer;

Open in new window


jeebu
0
 
Alpesh PatelAssistant ConsultantCommented:
var cust  = from objCustomer in customer
where (objCustomer.FirstName.Contains("Mark") || objCustomer.FirstName == null || objCustomer.FirstName == string.empty)
&& (objCustomer.LastName .Contains("Anthony") || objCustomer.LastName  == null || objCustomer.LastName  == string.empty)
&& (objCustomer.PostCode .Contains("12345k") || objCustomer.PostCode  == null || objCustomer.PostCode  == string.empty)
select objCustomer;
0

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now