none
Nice general purpose way to filter out non-printable characters? RRS feed

  • Question

  • I have an application which uses EF 4.1 which  uses the Self-Tracking Entity template to generate objects which are bound to a WPF UI.  I've recently detected a problem caused by non-printable characters making it through the UI and into the database.  I'm trying to identify the best way to solve this in a general-purpose way.  I want it to affect all properties in this project, and probably any I do in future.  The possiblity of users pasting unsafe characters from outside sources is unavoidable.

    I can think of at least a couple of ways of acheiving this filtering in the WPF domain (converters, customised textbox implementations) but that doesn't seem like the right approach and this isn't the right forum.  Creating a partial class for each object seems like a good idea but, with this particular template, I don't see any partial methods availble to intercept property changes.

    I doubt this kind of problem is particularly unusual, so I decided to ask here if anyone has any suggestions.  Thanks for your advice!

    Wednesday, July 27, 2011 6:29 PM

All replies

  • when save the entity to database, we can loop the entity's property to find the non-printable characters

     


    I am fish.
    Thursday, July 28, 2011 7:29 AM
  • Yeah, I guess I could iterate though all the changed entities before I call SaveChanges and use reflection to clean any public string properties.  That would be relatively easy to copy to new projects.  The only catch with this is that my properties always seem to have their ChangeTracker.State stuck on Added, so I can never see if they're modified.  Somehow this doesn't seem to bother the SaveChanges function - I've demonstrated that it only saves entities which have really changed.  Any idea how else I can tell whether the object has changed or has been added locally?
    Thursday, July 28, 2011 12:55 PM
  • Hi Hamish,

    Welcome!

    I'm not familiar with WPF, but I think we can MarkAs entities states when user update it(on UI). I think this link is help:

    http://msdn.microsoft.com/en-us/library/ff407090.aspx

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, August 1, 2011 8:34 AM
    Moderator
  • Hi,

    I am writing to check the status of the issue on your side. Would you mind letting us know the result of the suggestions?
    If you need further assistance, please feel free to let me know. I will be more than happy to be of assistance.
    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, August 5, 2011 8:52 AM
    Moderator