-1

Spent about 4 hours trying to figure this out without success.

IQueryable<userTOM> Infolist =  userTOMs();
        var rbtUserId = Infolist.Where(x => x.UserName == FormsUserName);

userTOMs <-- Does not exist. Remade the namespace many times but will not appear.

Felipe Oriani
  • 37,948
  • 19
  • 131
  • 194

1 Answers1

0

IQueryable does not run immediately on the database. In order to run the query, one has to run functions such as .ToList(), or .Count() on the IQueryable.

Therefore, nothing in your pasted code triggers the database request, and the ID will not be retrieved. I would modify your request to this:

IQueryable<userTOM> Infolist =  userTOMs();
userTOM rbtUser = Infolist.FirstOrDefault(x => x.UserName == FormsUserName);

Guid rbtUserId; //assuming this will be populated with a Guid value
if (rbtUser != null) {
    rbtUserId = rbtUser.Id; //assuming "ID" is the property name
}
Omri Aharon
  • 16,959
  • 5
  • 40
  • 58
  • I understand LINQ better now and will use this snippet. Thanks. The userTOM is NOT underlined while the userTOMs is still underlined in RED. :( I was hoping that I just needed to add something to the namespace code? – Thomas Mahoney Feb 27 '15 at 23:04
  • "The name 'userTOMs' does not exist in the current context " – Thomas Mahoney Feb 27 '15 at 23:35
  • Here it is in my class: public System.Data.Linq.Table userTOMs { get { return this.GetTable(); } } public System.Data.Linq.Table MessageStageTOMs { get { – Thomas Mahoney Feb 28 '15 at 00:40
  • Well it sounds like `userTOMs` is a table and you use it like a function.. so maybe change to `IQueryable Infolist = userTOMs.FirstOrDefault(x => x.UserName == FormsUserName);` ? – Omri Aharon Feb 28 '15 at 07:58
  • That did it. THANKS. I did not know the difference.. – Thomas Mahoney Feb 28 '15 at 15:27
  • @ThomasMahoney Glad to help. Since it's your first question on SO, I'd offer a quick explanation - if you find an answer useful, please upvote it (upper triagle above the number to the left of the question). If you have several answers to your question, or just one that you found useful and that solved your question, please also accept that answer by clicking the tick mark below the score of the answer. That way future visitors would know what helped you :) – Omri Aharon Feb 28 '15 at 17:05