c# - compare string from db to posted string -


i have db want part of (a name) not duplicated. i'm trying check if exist , if not save part, saving regardless if exists or not.

code:

var reviewsubject = c in db.subject select   c.subjectname.tostring().tolower(); var match = reviewsubject.firstordefaultasync(stringtocheck => stringtocheck.equals(model.sub.subjectname.tolower())); model.rev.created = datetime.now; if (modelstate.isvalid) {     if ((model.sub.subjectname.tolower()).equals(match))     {         //do nothing      }     else     {         model.sub.gbu = model.rev.gbu;         db.subject.add(model.sub);     } } 

you not using await keyword on result reviewsubject.firstordefaultasync returns task<t>. therefore checking if task equal string, false.

the correct usage be:

var match = await reviewsubject.firstordefaultasync(stringtocheck => stringtocheck.equals(model.sub.subjectname.tolower()));` 

if don't want use async method use synchronous 1 such:

var match = reviewsubject.firstordefault(stringtocheck => stringtocheck.equals(model.sub.subjectname.tolower()));` 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -