Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 200937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:09:19+00:00 2026-05-11T17:09:19+00:00

I have a linq query which returns the ID of a question based on

  • 0

I have a linq query which returns the ID of a question based on the questions text.
This ID is then needed to be used to relate a date in a date table to that particular question. The question is already stored and the date is stored at a different time.

The problem is that the query returns the questionID as an anonymous type and so when I need to assign that questionID as the questionID in another table, it throws an error, stating that the table is expecting a Guid. Following this, I converted the anonymous type to a string and then used the GUIDs convert feature to convert the string to a GUID, however it is now giving me the error that a GUID should be 32 characters and 4 dashes.

My thoughts regarding this are that the anonymous type is returning the questionID as “QuestionID = jkj939-89239829- etc etc.” – With the prefix of characters at the front, and thus when converting it to a GUID, the converted string contains these characters.

Have I missed something?
I really can’t understand why it would do this, and is there a way to remove the prefix returned by the anonymous type?
Help would be greatly appreciated.

Here is the code:

public static void GetQuesID(string quesText)
    {
        ExamineDataContext dc = new ExamineDataContext();
        var matchedques = from q in dc.GetTable<Question>()
                            where q.QuestionText.Contains(quesText)
                            select new{
                                q.QuestionID
                            };
        foreach (var element in matchedques)
        {
            MessageBox.Show(element.ToString());
        }

        try
        {
            Guid g = Guid.NewGuid();
            Table<DateLastUsed> dlused = Repository.GetDateLastUsedTable();
            DateLastUsed dlu = new DateLastUsed(); ;
            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();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:09:19+00:00Added an answer on May 11, 2026 at 5:09 pm

    Unless I’m missing something, why don’t you just select q.QuestionID instead of making a new anonymous-type wrapper?

    var matchedques = from q in dc.GetTable<Question>()
                                where q.QuestionText.Contains(quesText)
                                select q.QuestionID;
    
    foreach (var element in matchedques)
    {
        MessageBox.Show(element.ToString());
    }
    

    Alternatively, give the field a name (“theID” below) and access it directly:

    var matchedques = from q in dc.GetTable<Question>()
                                where q.QuestionText.Contains(quesText)
                                select new{
                                    theID = q.QuestionID
                                };
    
    foreach (var element in matchedques)
    {
        MessageBox.Show(element.theID.ToString());
    }
    

    Apparently, there was more to the question than I first thought. In response to the comment, keep in mind that you’re returning an enumeration of results in matchedques (hence the foreach above, right?). So the following line is also in error:

    string qidGuidString = matchedques.ToString();
    

    You either want

    string qidGuidString = matchedques.Single().ToString();
    

    if matchedques should contain a single result, or a foreach loop if matchedques should contain multiple results.


    Note that there’s no reason to convert a GUID to string and back again, and you can also use the query to return something more useful (namely, a new DateLastUsed object):

    var matchedques = from q in dc.GetTable<Question>()
                                where q.QuestionText.Contains(quesText)
                                select new DateLastUsed() {
                                    DLUID = Guid.NewGuid(),
                                    QuestionID = q.QuestionID,
                                    DateLastUsed1 = DateTime.Now
                                };
    
    Table<DateLastUsed> dlused = Repository.GetDateLastUsedTable();
    
    foreach(var dlu in matchedques)
    {
        dlused.InsertOnSubmit(dlu);
        dlused.Context.SubmitChanges();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this LINQ query which returns the indexes of all the items in
I have a Linq query which returns an ordered list. It works, but when
I have a LINQ query which returns a set of rows. The structure is:
I have a LINQ query which returns all the values inside a Dictionary, conditional
I have a LINQ query which returns IEnumerable<List<int>> but i want to return only
I have the following linq query which returns a Report Object; yet I need
I have a linq query which returns results ordered by first letter. Is there
I have a LINQ Query which returns a Boolean. Boolean status=true; var s =
I have a Linq query which returns all of the data stored in a
I have a LINQ query which creates an anonymous collection. One thing I'm returning

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.