0

I am trying to convert the following SQL statement to a Link2SQL statement.

SELECT * FROM Global.CustomData
WHERE CustomDataSource LIKE '%Plugin%'

I have converted it to this statement

    var query =
      from item in db.CustomDatas
      where item.CustomDataSource.Contains(dataSource)
      select item;

And have tried setting dataSource to the following: "Plugin", "%Plugin%", "/Plugin/" and "%/Plugin%/". These I have taken from other examples. Unfortunately, although the TSQL statement does return a value, I cannot get the Linq2Sql statement to return anything. Could someone tell me what I am doing wrong?

Tim
  • 2,731
  • 9
  • 35
  • 72

1 Answers1

2

You should pass "Plugin", the only thing I can think of is the case sensitivity. Try something like this:

where item.CustomDataSource.ToLower().Contains(dataSource.ToLower())
AD.Net
  • 13,352
  • 2
  • 28
  • 47
  • I tried that but still no luck. I also commented out my where clause, to confirm that I was getting data, and received two lines, one of which had a CustomDataSource of "Plugin-0". I don't think it makes a difference, but I am using .Net 4.0. – Tim Jul 25 '14 at 00:22
  • Make sure you point to the right database. Even without `.ToLower()` it should work since the SQL generated for `Contains` is like your SQL. Actually `ToLower` might throw exception when running against database. – AD.Net Jul 25 '14 at 00:27
  • It didn't throw an exception, but I'll remove it anyway. The case does match. Removing the WHERE clause confirmed that I was pointing to the correct database. Thank you for your help. – Tim Jul 25 '14 at 00:31