© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•14mo ago•
8 replies
surwren

Data Retrieval in a SignalR Hub/Service?

I am used to repo -> service -> controller MVC models, and I do not have much experience with in-memory retrieval beyond using LinQ.

Say I have a class which could have multiple queryable fields:

        public string SignalRId { get; set; }
        public int UserId { get; set; }
        public string Nickname { get; set; }
        public string Region { get; set; }
        public string RoomName { get; set; } 
        public string SignalRId { get; set; }
        public int UserId { get; set; }
        public string Nickname { get; set; }
        public string Region { get; set; }
        public string RoomName { get; set; } 


In a normal appcontextdb access scenario, I would just pull out the values using EFCore LinQ using something like

var user = await _context.Users.FirstOrDefaultAsync(u => u.UserId == UserId)
var user = await _context.Users.FirstOrDefaultAsync(u => u.UserId == UserId)


In my SignalR Hub, I am using an in-memory method and not SQL to store my data since I don't expect users to have long-lasting data (unlikely they will maintain a connection for >5minutes per session). Therefore I inject a
ConnectedClientsService
ConnectedClientsService
and don't have a DB table.

- Is using
FirstOrDefaultAsync
FirstOrDefaultAsync
with regular IQueryable is more standard practice in this case (for example, searching for strings matching region, etc)?
- Is it standard practice to use 2 concurrent dictionaries with a lock to enable O(1) access?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ SignalR in a background service
C#CC# / help
2y ago
❔ Blazor Server + Custom SignalR hub
C#CC# / help
3y ago
Blazor Server with Custom SignalR Hub
C#CC# / help
4mo ago
Data retrieval EF-core
C#CC# / help
15mo ago