C# Linq Guid Anonymous Type Problem -
I have a Linux query that gives the ID of the question based on questions of questions. Then it is necessary to use this ID for that specific question to be related to a date in the date table. The question is already stored and the date is stored at different times.
The problem is that the question gives questionID as an anonymous type and so when I have to specify that question id in another table, it throws an error, stating that the table is a Looking forward to the Gid, after that, I converted the anonymous type into a string and then used to convert the string to a GUID to use the GUID, however now let me do this tray Giving that GUID should be 32 characters and 4 dashes.
My idea of this is that the anonymous type is returning the question ID as "Question id = jkj939-89239829-etc etc" - With the prefix of front-facing letters, and so on when it is converted to GUID, the converted string contains these characters.
Am I missing something? I really do not understand why it will do this, and is there a way to remove the prefix given by anonymous type? The help would be greatly appreciated.
Here is the code:
Public static zero GetQuesID (string quesText) {ExamineDataContext dc = new ExaminationDataContext (); Var matchedques = q to dc.getTable & lt; Question & gt; () Where q.QuestionText.Contains (quesText) select new {q.QuestionID}; Forex Currency (Miscellaneous Elements in Matched) {Message Box. Show (element. Toaster); } {Good G = Good. Newguide (); Table of the & lt; DateLastUsed & gt; Dlused = Repository GetDateLastUsedTable (); DateLastUSD DLU = New Date Use (); ; String qidGuidString = matchedques.ToString (); Guid convQuesGuid = New Guid (qidGuidString); Dlu.DLUID = G; Dlu.QuestionID = convQuesGuid; Dlu.DateLastUsed1 = DateTime.Now; Dlused.InsertOnSubmit (DLU); Dlused.Context.SubmitChanges (); } Hold (Exceptional) {East; }}
Unless I'm missing something, you can only Instead of creating a new anonymous-type wrapper, select q.QuestionID
var matchedques = q to dc.getTable & lt; Question & gt; () Where q.QuestionText.Contains (QuesText) select q.QuestionID; Forex Currency (Miscellaneous Elements in Matched) {Message Box. Show (element. Toaster); } Alternatively, give the field a name (" theID " below) and access it directly:
Var matchedques = Q to dc.gettable & lt; Question & gt; () Where q.QuestionText.Contains (quesText) select new {theID = q.QuestionID}; Foreign Currency (Miscellaneous Elements in Matchedcuques) {Message Box. Show (element.theID.ToString ()); } Apparently, I had thought more about the question than before. In response to the comment, keep in mind that you are returning an count of the result (hence above foreach, right?), Then the following line is also in error:
String qidGuidString = matchedques.ToString (); You want
string qidGuidString = matchedques.Single (). ToString (); If there should be a single result in the mattex, or there should be multiple results in the matchedcube, then
Note there is no reason to change the GUID string And back again, and you can also use the query to return some more useful (i.e. a new DateLastUsed object):
var matchedques = q DC from .GetTable & lt; Question & gt; () Where q.QuestionText.Contains (quesText) select the new DateLastUsed () (DLUID = Guid.NewGuid (), QuestionID = q.QuestionID, DateLastUsed1 = DateTime.Now}; Date of dateLastUsed & gt; Dlused = Repository.getDateLastUsedTable (); Foreign exchange (version DLU) in MEDDQUE {dlused.InsertOnSubmit (dlu); dlused.Context.SubmitChanges ();}
Comments
Post a Comment