surwren
Explore posts from servers✅ Mocking DB operations
Say I have a function and I need to verify that the saved UserFollow object will:
1. Cause the user objects to be retrieved if UserFollow retrieves them eagerly
2. Cause the userFollow to be retrieved if a User is retrieved with said fields eagerly
public async Task<bool> AddFollowerByPrivateIdAsync(int userPrivateId, int followerPrivateId) {
var user = await _context.Users.FirstOrDefaultAsync(u => u.PrivateId == userPrivateId);
var follower = await _context.Users.FirstOrDefaultAsync(u => u.PrivateId == followerPrivateId);
if (user == null || follower == null) {
return false;
}
var userFollow = new UserFollow {
FollowedId =
[user.Id
]FollowerId =
[follower.Id
]
Type = FollowType.Requested,
Followed = user,
Follower = follower
};
_context.UserFollows.Add(userFollow);
await _context.SaveChangesAsync();
return true;
}
How would I test this? I have looked at XUnit and MockItEasy but it doesn't look like they are dealing with the Database, but rather dependencies for abstracted code.134 replies
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:
In a normal appcontextdb access scenario, I would just pull out the values using EFCore LinQ using something like
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
and don't have a DB table.
- Is using 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?9 replies
Bottlenecks in a SignalR Implementation for Managing Room Data?
I am using SignalR to manage real-time room data in a small practice app that I may have plans to scale up in the future.
The current implementation involves an in-memory dictionary where each room is mapped to a HashSet<userId> to track users in the room. So far, this does not seem like a bottleneck.
However, I suspect the number of persistent connections (SignalR maintaining a connection for each user) might become a scalability issue if I scale up. I am running it via dockerized .NET server on a cloud CVM with 4GB ram
Are there other common bottlenecks or pitfalls I should be aware of when scaling SignalR for this purpose?
Any advice or best practices for optimizing SignalR are appreciated
34 replies
Can .NET controllers accept binary data? Should they?
I have already done EFcore mapping for
- user
- post
- media
Currently the client posts to server and COS separately.
I was wondering if there was a way to streamline post creation, such that the client sends the media together with the db update (to the server), and then the server can do both the db upload and cos upload in a transaction of some sort?
Is this possible or advised?
8 replies
Controller methods that rely on JWT authentication using another service
Is there a way to handle these methods without writing so much duplicated code?
For example CRUD methods like this:
I need to repeat this chunk over and over in every method that relies on the JWT:
What other ways are there?
10 replies
Proper way to deploy application?
So right now I scp my entire project to the CVM, build and then docker compose up
The scp parts takes absolutely forever it's outrageous (project is about 117+mb)
Am I stupid and just doing this wrong? Am I missing something? I haven't explored CICD pipelines yet
17 replies
My constructor sets the attribute, so why is EFcore complaining?
why is EFCore complaining?
Required member 'UpMedia.OwnerId' must be set in the object initializer or attribute constructor.
Required member 'UpMedia.Owner' must be set in the object initializer or attribute constructor.
Here:
var upMedia = new UpMedia(upMediaDto.Type, user, upMediaDto.Bucket, upMediaDto.Path);
My code is
???????47 replies
EFCore is incapable of connecting to DB despite everything else being able to
Mystifying me because
- SSMS connects fine
- Migration commands like
Add-Migration "Add_Table"
and Update-Database
work fine
can also be viewed from DB side.
I am always encountering this error from EFCore when I run the application:
Code will be in responses10 replies
Entity Framework Core: How to build without Package Manager Commands?
I am looking at this sample project : https://github.com/Nedal-Esrar/Travel-and-Accommodation-Booking-Platform
I notice that it automatically creates the TABP table as long as the connection string goes through, which is not the same for other EFCore projects I have created in the past in .NET 8.0.
I have always needed to manually do
Add-Migration "Add_Tables"
and Update-Database
but it seems this project does not?
I did ctrl + shift + f but I do not see any scripts for the aforementioned commands.
What dark magic is this project doing that bypasses the migrations step?6 replies
Refactoring Similar Network Requests
I have 3 async methods with a great deal of similarities but some differences (some use Authorization token, some have Json payload, some return Task<bool>, others Task) but all make network requests in a similar flow.
What is an approach I could use to refactor them?
93 replies
Deployment vs production environments
I am preparing for a .NET role and am wondering what some configurations/setups/tools I can look up or prepare for?
For context:
The company is using .NET and Azure. Development is done via login to a VMware portal (IDE and environment are setup inside said VM) and there are a series of CICD tools facilitating any code pushes within said VMware portal.
What deployment/production configurations or tools should I look into?
3 replies