Thanks for any insights you can help with!
Very simply, I'm calling a set of Contacts from the Databa开发者_如何学JAVAse using LinqToSql. Two of those columns "FirstName" and "LastName" are encrypted.
I decrypt them on the fly as you see in the included code. However, I also want to filter based on LastName. The problem is if I do a compare in the statement, it's comparing the encrypted value to the text value.
I need to somehow get the resulting data for my gridview, then filter it after the fact, not based on the database values again, but with the data (and decrypted data) that I already have.
Ideas?? Thanks!
protected void ContactsLDS_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
DatabaseDataContext db = new DatabaseDataContext();
MyAES aes = new MyAES();
var v1 = from s in db.Contacts
select new Contact()
{
ContactId = s.ContactId,
FirstName = (s.FirstName == null ? "" : aes.DecryptString(s.FirstName)),
LastName = (s.LastName == null ? "" : aes.DecryptString(s.LastName)),
};
e.Result = v1;
}
These two posts helped me answer this:
Linq "Could not translate expression... into SQL and could not treat it as a local expression."
Gridview using a generic list as DataSource and Auto-generating columns
I just ended up grabbing the data in encrypted format to start with, then running a second query over it and decrypting it. Finally, when I wanted to filter the data, I'd run a 3rd over, running the "where str.startswith()".
A bit of extra processing, but get's the job done.
精彩评论