Can't remove Contains() handler from SqlFunctionCallHandler - why?

I'm trying to amend some Entity Framework functionality at runtime by using reflection.
The following code snippets I've been using to get some feeling for the Entity Framework's internal functionality. Please don't ask what I'm using this for - at this stage it's just a test anyway.
My code is supposed to remove the Contains() handler from Entity Framework, so a query like this shall fail:
foreach (T1 a in (from x in ctx.t1
where x.Name.Contains("Man")
select x).DefaultIfEmpty()) if (a != null) Console.WriteLine(a.Name);
However, I don't seem to be able to remove the Contains handler at run-time.
Can someone please enlighten me on why this doesn't work?
Here's the code I've been using (I've omitted as much as I could to make the code snippet small):
using System;
using System.Data.Entity;
using System.Data.Entity.SqlServer;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
namespace EF_Contains_Override
internal class Program
static private void removeContains()
Type type = Assembly.GetAssembly(typeof(SqlFunctions)).GetType("System.Data.Entity.SqlServer.SqlGen.SqlFunctionCallHandler");
FieldInfo fi = type.GetField("_canonicalFunctionHandlers", BindingFlags.Static | BindingFlags.NonPublic);
object functionHandlerList = fi.GetValue(null);
MethodInfo method = functionHandlerList.GetType().GetMethod("get_Item", new Type[] { typeof(string) });
object origContains = method.Invoke(functionHandlerList, new object[] { "Contains" });
method = functionHandlerList.GetType().GetMethod("Remove", new Type[] { typeof(string) });
Debug.Assert((bool)method.Invoke(functionHandlerList, new object[] { "Contains" }));
static private void Main(string[] args)
Database.SetInitializer<EFContains>(new MyInitializer());
removeContains();
using (EFContains ctx = new EFContains())
foreach (T1 a in (from x in ctx.t1
where x.Name.Contains("Man")
select x).DefaultIfEmpty()) if (a != null) Console.WriteLine(a.Name);
Console.WriteLine("Press any key to continue ...");
Console.ReadKey();
Given the following seed, the above select should throw an exception because a Contains() handler no longer exists:
using System.Data.Entity;
namespace EF_Contains_Override
public class MyInitializer : DropCreateDatabaseAlways<EFContains>
protected override void Seed(EFContains context)
context.t1.AddRange(new[] { new T1("Hey Man"), new T1("No, woman, no cry") });
context.SaveChanges();
Still people out there alive using the keyboard?
Working with SQL Server/Visual Studio/Office/Windows and their poor keyboard support they seem extinct...

Hello BetterToday,
With your provided code and the resource code of Entity Framework downloaded from
here, I created a similar query with yours:
using (DFDBEntities db = new DFDBEntities())
var result = (from o in db.TestTables
where o.TestName.Contains("1")
select o).ToList();
With the resource, the all method are called to help generate the T-SQL are:
SqlGenerator.GenerateSql, SqlGenerator. VisitExpressionEnsureSqlStatement, SqlGenerator. VisitFilterExpression,
 and in the SqlGenerator.Visit, we see that it converts the Contains to the Like filer and then it called method is WriteSql, we can see that the static class System.Data.Entity.SqlServer.SqlGen.SqlFunctionCallHandler is not called, so it
would does not affect query even after removing the contains method.
After searching more, my consult is that for methods as Contains/StartWith/EndWith and some other methods could be translated to TSQL directly, this behavior are by designed.
You could try with other method as the 'TOLOWER' as:
static void Main(string[] args)
try
#region https://social.msdn.microsoft.com/Forums/en-US/82aaca54-f1cd-47d3-b97c-254ec7b3e8bf/cant-remove-contains-handler-from-sqlfunctioncallhandler-why?forum
removeContains();
using (DFDBEntities db = new DFDBEntities())
var result = (from o in db.TestTables
where o.TestName.ToLower() == "1"
select o).ToList();
#endregion
catch (Exception)
static private void removeContains()
Type type = Assembly.GetAssembly(typeof(SqlFunctions)).GetType("System.Data.Entity.SqlServer.SqlGen.SqlFunctionCallHandler");
FieldInfo fi = type.GetField("_canonicalFunctionHandlers", BindingFlags.Static | BindingFlags.NonPublic);
object functionHandlerList = fi.GetValue(null);
MethodInfo method = functionHandlerList.GetType().GetMethod("get_Item", new Type[] { typeof(string) });
object origContains = method.Invoke(functionHandlerList, new object[] { "ToLower" });
method = functionHandlerList.GetType().GetMethod("Remove", new Type[] { typeof(string) });
Debug.Assert((bool)method.Invoke(functionHandlerList, new object[] { "ToLower" }));
It would throw an which says “{"'TOLOWER' is not a recognized built-in function name."}” I think it is you except.
Regards.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.

Similar Messages

  • How can i remove a card from iTunes ?

    How can i remove a card from iTunes ?

    If you want to remove a credit/debit card from your account then on your computer's iTunes you should be able to edit your payment info by going into the Store > View Account menu option and logging into your account, and on your account's details page there should be a payment link.  If you are doing it on your iOS device then tap on your id in Settings > iTunes & App Store and tap on 'View Apple ID' on the popup and log into your account  - that should also give you a payments link on your account's page.
    Changing payment info : Change or remove your payment information from your iTunes Store account (Apple ID)
    If you don't get the 'none' option on the payment details screen : Why can’t I select None when I edit my Apple ID payment information?

  • How can I remove the battery from my Iphone and Ipads?

    How can I remove the battery from my iphone and ipad?

    The iPhone and iPad do not have user serviceable batteries. Battery replacement is handled by Apple. Make an appointment at the Genius Bar if battery replacement is required.

  • How can we remove the commas from the Formula value in SAP BW BEx query

    Hi All,
    How can we remove the commas from the Formula value in SAP BW BEx query
    We are using the formula replacing with characteristic.The characteristic value needs to be display as number with out commas.
    Regards
    Venkat.

    Do you want to remove the commas when you run the query on Bex Web or in RSRT?
    Regards

  • HT202667 how can I remove credit card from apple id ?

    i don't want to use apple id with credit card anymore i purchased enough apps for my apple device so now i wanna remove it so how can i remove credit card from apple id

    On your computer's iTunes you should be able to edit your payment info by going into the Store > View Account menu option and logging into your account, and on your account's details page there should be a payment link.  If you are doing it on your iPhone then tap on your id in Settings > iTunes & App Store and tap on 'View Apple ID' on the popup and log into your account  - that should also give you a payments link on your account's page.
    Changing payment info : http://support.apple.com/en-gb/HT1918
    If you don't get the 'none' option on the payment details screen : http://support.apple.com/en-gb/TS5366

  • How can I remove credit card from itunes account?

    How can I remove credit card from itunes account?

    I'm not home right now, so don't have iTunes here. I am basing this on having to do this a few days ago, as well as pictures from Google Images, so things may have different names now...
    Store (dropdown at top of iTunes screen)>View my account>Edit Payment Information>In the list of types of credit cards, the one at the far right says "None." Click that.

  • How can I remove some themes from Keynote??

    How can I remove some themes from Keynote??

    What a co-incidence... I just deleted those same goodies. They were in /Library/Application Support/Keynote-folder on my machine. I just deleted the whole folder, cause there seemed to be nothing more but those downloaded files. And Keynote worked great afterwards. There seemed to be another folder for iWork09, which is not to be removed.

  • HT5622 We have two iphones with the same Apple ID. Since I installed iOS this morning I have started receiving all my sons texts and when I send him a text it is delivered to both of us. How can I remove my phone from the joint Apple ID and remove myself

    My son and I both have iphones with the same Apple ID. Since I installed iOS this morning I have started receiving all my sons texts and when I send him a text it is delivered to both of us. How can I remove my phone from the joint Apple ID and remove myself from finding out what he is up to during Freshers week!

    You have to use a different Apple ID for your son.
    Read this note:
    iOS 5 & iCloud Tips: Sharing an Apple ID With Your Family
    still valid for ios 7

  • I have lost my phone IMEI  Number 012546005322381, Serial Number 87******A4S, is there a way it can be tracked? Also, how can one remove the device from the itunes account

    I have lost my phone IMEI  Number 012546005322381, Serial Number 87******A4S, is there a way it can be tracked? Also, how can one remove the device from the itunes account
    <Serial Number Edited By Host>

    If you enabled Find my iPhone then you should use that. If not, I'm afraid you're out of luck for finding it. 
    To manage your devices, go to Your Account in iTunes.

  • How can I remove a device from my iCloud/Apple ID?

    Hi,
    I merged my dad's iphone to my Apple ID a while back because he wants to buy an app and I have some credit left over so I let him used my ID on his device. Apparently, all my contacts, pictures from photo stream, and ical are now also in his device. And all his contacts, pictures, and ical are on mines. How can I remove his device from my icloud and Apple ID WITHOUT deleting anything? Like I just don't want him to get anymore of my reminders and contacts, and pictures? Because I'm afraid taht if I remove his iphone on my icloud, all the pictures/contacts/ical that he took and went to my device too will be deleted because those are some important pictures/contacts/ical?
    I tried to manually delete some of my dad's contacts that was shared on my phone, it turns out that it got deleted on his phone as well and vice versa. How can I just completely cut him off of my icloud and ID without losing any of my and his contacts/pics/etc?

    Dr mizooo_1985 wrote:
    And i didn' erase anything,
    Hope her new BF is not a forensics expert .
      Can she see my icloud-backups???
    Not unless she knows your Apple ID/Password...or her new BF is good at forensics.
    What can i do to prevent icloud-backup to this pc???
    Same as my last answer...good luck.

  • HT201317 How can I remove Photo Stream from my PC?

    How can I remove Photo Stream from my PC?

    Go to the iCloud control panel for windows (Start>Control Panel, search for "iCloud", double-click the iCloud icon), then uncheck Photo Stream.

  • How can I remove an iPhone from my apple account

    How can I remove an iPhone from my apple account

    Hello lindaharris
    If you want to not have an association with your Apple ID and your iPhone, check out the article below for the steps to do this.
    iTunes Store: Associating a device or computer to your Apple ID
    http://support.apple.com/kb/ht4627
    Thanks for using Apple Support Communities.
    Regards,
    -Norm G.

  • A friend of mine uses my apple id. he's getting same imessages beeing sent to me. how can i remove his device from my account

    a friend of mine uses mi apple id. he's getting same imessages beeing sent to me. how can i remove his device from my account

    Using FaceTime http://support.apple.com/kb/ht4319http://support.apple.com/kb/ht4319
    Troubleshooting FaceTime http://support.apple.com/kb/TS3367http://support.apple.com/kb/TS3367
    The Complete Guide to FaceTime + iMessage: Setup, Use, and Troubleshooting
    http://tinyurl.com/a7odey8http://tinyurl.com/a7odey8
    Troubleshooting FaceTime and iMessage activation
    http://support.apple.com/kb/TS4268http://support.apple.com/kb/TS4268
    iOS: FaceTime is 'Unable to verify email because it is in use'
    http://support.apple.com/kb/TS3510http://support.apple.com/kb/TS3510
    Using FaceTime and iMessage behind a firewall
    http://support.apple.com/kb/HT4245http://support.apple.com/kb/HT4245
    iOS: About Messages
    http://support.apple.com/kb/HT3529http://support.apple.com/kb/HT3529
    Set up iMessage
    http://www.apple.com/ca/ios/messages/http://www.apple.com/ca/ios/messages/
    iOS and OS X: Link your phone number and Apple ID for use with FaceTime and iMessage
    http://support.apple.com/kb/HT5538http://support.apple.com/kb/HT5538
    How to Set Up & Use iMessage on iPhone, iPad, & iPod touch with iOS
    http://osxdaily.com/2011/10/18/set-up-imessage-on-iphone-ipad-ipod-touch-with-io s-5/http://osxdaily.com/2011/10/18/set-up-imessage-on-iphone-ipad-ipod-touch-with-io s-5/
    Set Up Alert Sounds
    http://www.quepublishing.com/articles/article.aspx?p=1873027&seqNum=3http://www.quepublishing.com/articles/article.aspx?p=1873027&seqNum=3
    Extra FaceTime IDs
    http://tinyurl.com/k683gr4http://tinyurl.com/k683gr4
    Troubleshooting Messages
    http://support.apple.com/kb/TS2755http://support.apple.com/kb/TS2755
    Troubleshooting iMessage Issues: Some Useful Tips You Should Try
    http://www.igeeksblog.com/troubleshooting-imessage-issues/http://www.igeeksblog.com/troubleshooting-imessage-issues/
    Setting Up Multiple iOS Devices for iMessage and Facetime
    http://macmost.com/setting-up-multiple-ios-devices-for-messages-and-facetime.htmhttp://macmost.com/setting-up-multiple-ios-devices-for-messages-and-facetime.htm l
    FaceTime and iMessage not accepting Apple ID password
    http://www.ilounge.com/index.php/articles/comments/facetime-and-imessage-not-acc epting-apple-id-password/http://www.ilounge.com/index.php/articles/comments/facetime-and-imessage-not-acc epting-apple-id-password/
    Fix Can’t Sign Into FaceTime or iMessage iOS 7
    http://ipadtutr.com/fix-login-facetime-imessage-ios-7/http://ipadtutr.com/fix-login-facetime-imessage-ios-7/
    FaceTime, Game Center, Messages: Troubleshooting sign in issues
    http://support.apple.com/kb/TS3970http://support.apple.com/kb/TS3970
    Unable to use FaceTime and iMessage with my apple ID
    https://discussions.apple.com/thread/4649373?tstart=90https://discussions.apple.com/thread/4649373?tstart=90
    How to Block Someone on FaceTime
    http://www.ehow.com/how_10033185_block-someone-facetime.htmlhttp://www.ehow.com/how_10033185_block-someone-facetime.html
    My Facetime Doesn't Ring
    https://discussions.apple.com/message/19087457#19087457https://discussions.apple.com/message/19087457#19087457
    How to watch FaceTime calls on the big screen with Apple TV
    http://www.imore.com/daily-tip-ios-5-airplay-mirroring-facetimehttp://www.imore.com/daily-tip-ios-5-airplay-mirroring-facetime
    Send an iMessage as a Text Message Instead with a Quick Tap & Hold
    http://osxdaily.com/2012/11/18/send-imessage-as-text-message/http://osxdaily.com/2012/11/18/send-imessage-as-text-message/
    To send messages to non-Apple devices, check out the TextFree app https://itunes.apple.com/us/app/text-free-textfree-sms-real/id399355755?mt=8https://itunes.apple.com/us/app/text-free-textfree-sms-real/id399355755?mt=8
    How to Send SMS from iPad
    http://www.iskysoft.com/apple-ipad/send-sms-from-ipad.htmlhttp://www.iskysoft.com/apple-ipad/send-sms-from-ipad.html
    How to Receive SMS Messages on an iPad
    http://yourbusiness.azcentral.com/receive-sms-messages-ipad-16776.htmlhttp://yourbusiness.azcentral.com/receive-sms-messages-ipad-16776.html
    You can check the status of the FaceTime/iMessage servers at this link.
    http://www.apple.com/support/systemstatus/http://www.apple.com/support/systemstatus/
     Cheers, Tom

  • Somebody uses my apple id for facetime on his iphone how can i remove his phone from my account?

    somebody uses my apple id for facetime on his iphone how can i remove his phone from my account?

    Last Spring I received a couple of emails to an alias I set up a long time ago under mac mail with mac.com - not my main ID - at mac.com.   The mail had the Icloud extension.     I just deleted it.
    I then received a couple of e-mails forwarded to the same alias that came from a non-apple account that led me to search to see if the company was legit - it was.     Using a non-apple hidden account I sent that non-apple account an email informing them apparently when they registered the ID or alias as an ICLOUD extension - apple did not check for duplication in accounts or aliases that were not in the Icloud.
    I also sent feedback to Apple telling them to fix it and apparently they did - along with the person who replicated my alias.
    On this site there were a number of postings from people who also had problems with mac mail and Icloud who resolved it by contacting Apple and getting the accounts cleared up.

  • How can I remove a podcast from iTunes if iTunes is locked up.

    I added a password protected podcast and iTunes locks up on the authentication dialog. Spinning beachball... only thing I can do is force quit.
    Earlier solution was to go in and manually disable podcasts with Xcode. but then i can't play any of my podcasts.
    The recent itunes update fixed the problem, sort of. it allowed me to use itunes normally again. But, I tried to subscribe to the podcast agin and... yup, same thing.
    How can I remove that podcast from iTunes without using iTunes to remove it?
    HELP!!!!

    ROGER, I AM SORRY I DIDN'T GIVE YOU THE 10 POINT RATING. I DIDN'T REALIZE IT MADE A DIFFERENCE AND THE PROBLEM I HAVE IS NOT WITH YOUR RESPONSE, WHICH WAS RIGHT ON, BUT WITH THE WAY THE SYSTEM WORKS.
    REGARDS, JEANNE

Maybe you are looking for

  • How to find documents stored on iCloud?

    I am trying to find any and all of my documents on iCloud. This feels like the silliest question, yet I cannot recall and find only Pages, and Contacts and none of my past work. 

  • ADFC-10001 Error while creating user in oim

    Hi All, I am getting ADFC-10001: cannot instantiate class 'oracle.iam.identitytaskflow.backing.taskflows.createuser.createuserview' error while creating user. ADF_FACES-60097:For more information, please see the server's error log for an entry beginn

  • IOS 8 WiFi and Keyboard problems

    Sorry for my english, I'm from Russia. After updating my iPhone 5 started very fast discharge (the same thing I found on the iPad Air). Just Wifi was much weaker ,signal catches very very bad.More.. side of the keyboard do not work correctly, they fl

  • JDeveloper to WebLogic Server 6.1 connectivity problem

    Hello, I am try to connect to WebLogic Server 6.1 from JDeveloper Version 9.0.3.9.93. The JDeveloper is installed in Windows XPe. The WebLogic Server is installed in a Sun Box. The weblogic.jar is already in the lib/ext directory in my local machine

  • Enevlope will not print

    I own an HP Laserjet 1018. I'm running Vista Home Premium.  I have the latest print drive installed.  when i open MS Word and go to mailings then enevlopes, select the size, enter the information, insert the enevlope into the slot to print and enevlo