• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1060
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

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