You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working on my ASP.NET Core MVC project, but I am facing an issue where newly created entries are not being saved to the database. I have set everything up correctly, and I can see the database and tables in SQL Server Management Studio 2022. However, when I try to create a new category or product, it doesn't save. if i manually enter the data to Database then it shows up what is available. only the data entering to the database doesnt work.
Problem Statement:
Despite having correctly configured the database and tables (verified in SQL Server Management Studio 2022), I cannot save new entries to the database through my application. I have installed the necessary Entity Framework packages: Microsoft.EntityFrameworkCore.SqlServer, Microsoft.EntityFrameworkCore.Tools, Microsoft.EntityFrameworkCore.Design, and Microsoft.EntityFrameworkCore.
Question:
What could be causing the issue where new entries do not save to the database? Are there any common pitfalls or configurations I might have missed that could lead to this problem?
Any help or insights would be greatly appreciated!
`using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace RelationshipRetry.Models
{
public class Category
{
public int CategoryId { get; set; }
[Required]
public string Name { get; set; }
public ICollection<Product> Products { get; set; }
}
}`
Models/Product.cs
`using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace RelationshipRetry.Models
{
public class Product
{
public int ProductId { get; set; }
[Required]
public string Name { get; set; }
[ForeignKey("Category")]
public int CategoryId { get; set; }
public Category Category { get; set; }
}
}`
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm working on my ASP.NET Core MVC project, but I am facing an issue where newly created entries are not being saved to the database. I have set everything up correctly, and I can see the database and tables in SQL Server Management Studio 2022. However, when I try to create a new category or product, it doesn't save. if i manually enter the data to Database then it shows up what is available. only the data entering to the database doesnt work.
Problem Statement:
Despite having correctly configured the database and tables (verified in SQL Server Management Studio 2022), I cannot save new entries to the database through my application. I have installed the necessary Entity Framework packages: Microsoft.EntityFrameworkCore.SqlServer, Microsoft.EntityFrameworkCore.Tools, Microsoft.EntityFrameworkCore.Design, and Microsoft.EntityFrameworkCore.
Question:
What could be causing the issue where new entries do not save to the database? Are there any common pitfalls or configurations I might have missed that could lead to this problem?
Any help or insights would be greatly appreciated!
Repo:
https://github.com/SheshanFernando2021/RelationshipRetry.git
code:
Models/Category.cs
Models/Product.cs
Views/Categories/Create.cshtml
Views/Products/Create.cshtml
appsettings.json
Program.cs
Data/RelationshipRetryContext.cs
CategoriesController.cs
ProductsController.cs
Beta Was this translation helpful? Give feedback.
All reactions