How to get current User outside of Controller in another layer
In ASP.NET Core 6, I need to get the current user in service layer This is code: public class ServiceModel { private readonly IHttpContextAccessor accessor; public ServiceModel(IHttpContextAccessor accessor) { this.accessor =…
how to fix Net Framework 3.5 and 4.5 error 0x80070002
how to fix Net Framework 3.5 and 4.5 error 0x80070002
Cannot Migrate Database
Hello all, I am having issue updating the migration of my database. I am currently using .NET 9.0. I have modified one of my files to include the following: protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.UpdateData( …
Using IDENTITY_INSERT with FK_ChildTable_ParentTable?
Hello, Wrapping SaveChanges with ON and OFF works fine with individual tables. But not in case of a parent-child relationship where a foreign key exists. Microsoft.Data.SqlClient.SqlException (0x80131904): Cannot insert explicit value for identity column…
Scaffolding (DB first) does not generate Model class
Hi I tried to generate model class based on existing view. This is the command I used in PMC: Scaffold-DbContext "//connectionstring" Oracle.EntityFrameworkCore -schema //schema -table //table -OutputDir Models It seems like it is working.…
Can't Remove-Migration because of default ID (but Add-Migration worked fine)
I messed up the seed data, and now when I try the "Remove-Migration" command I get this error. The "Add-Migration" command gave me no problems, however. Is this an error? How can I remove the migration? Unable to create a 'DbContext'…
How to fix .NET Framework error
keeps saying See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box. ************** Exception Text ************** System.Data.Entity.Core.EntityException: The underlying provider failed on Open.…
How to fix DbContextOptions resolving properly from services to apply EF migration to create database?
I'm trying to run a migration to create my initial database from code, but i'm having difficulties with proper registration of DbContextOptions. My program.cs contains the service registration: var builder = WebApplication.CreateBuilder(args); // Add…
Upload Image to ASP.NET Razor Page
Hello, How to add image upload in asp.net core razor pages to a Create and Edit page that is generated from: Add > New Scaffolded Item > Razor Pages using Entity Framework (KRUD) to save the name of image to database and upload image file to…
How can I post multiple entries at once, when selecting multiple options from a Multi List Dropdown
Hi All, I have hit a bit of a snag with this. I have a form, which contains a multi select dropdown menu. I want to allow the user to select as many options from the drop down menu and upon pressing submit, each different item selected will be saved into…
Getting an error :Add-Migration : The term 'Add-Migration' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Tried trouble shooting , verfied DB context class. Reinstalled Vs after troubleshooting and getting answers saying there is a problem with package manager .
Entity Framework Core 8, table with a user-defined data type. UDT
We are migrating a 4.5 large application which uses sql data reader to query the MS SQL database to .NET 8 EF core. The database has at least one user-defined column, code below. There is currently 20 years of data in the database. We are migrating…
how to include a spatial index in c# EF
This query is not using the spatial index: (@__point_0 sys.geometry)SELECT TOP(1) [t].[Id], [t].[Bus_StopsId], [t].[Point] FROM [TripRef_Stops] AS [t] WHERE [t].[Point].STBuffer(5.0000000000000002E-05).STContains(@__point_0) = CAST(1 AS bit) - it is…
Using Enity Framework 6.1 and initial query VERY slow.
When performing the initial query using EF, it can take up to 9 mins. Though if you rerun it again and again it takes seconds. If I capture the query from the profiler, it always runs in seconds. If I wait about 10 / 15 mins the slow initial process…
Map only the selected columns when using EntityFramework
In my recent Entity Core project I am having database table called "YmPlant" and it has 20+ columns. But for my requirement I just need data only from 3 columns. Also I am not required to do the write operations. Only read from YmlPlant table. …
How to Optimize Database Interactions in Entity Framework Core?
I am using Entity Framework Core for database interactions in my .NET application. I am seeking advice on optimizing database queries and transactions for better performance and efficiency. Any tips or best practices would be appreciated.
.Net Framework > .Net Migration Problem - Incremental upgrade with Entity Framework 6.4.4
Hi, (apologies for the lengthy description) I'm working on setting a roadmap for a phased/incremental upgrade path of a .Net Framework 4.8 solution to .Net 8.0+. The existing solution has a large number of projects with direct project references and has…
How to use EF Core when two properties in the Principle entity point to the same attribute in the dependent entity?
I have 2 Model classes: Department.cs cs public class Department { public string DepartmentId { get; set; } public string Name { get; set; } public string Description { get; set; } [ForeignKey("FacultyId")] public…
Invalid UserName in ASP.NET Core 6
I am working on an ASP.NET Core 6 MVC application that uses ASP.NET Core Identity. When I try to create a new user using the UserManager, I get this error: User name ' ' is invalid, can only contain letters or digits Username do not has any…
Cycling problem
Hi, I have 2 entity which have one to many relation between. Lets name them School and student. When I'm creating School I'm getting cycling problem . I did all the configuration in Configure class but nothing worked. There is a way with [JsonIgnore] but…