Posts

Showing posts from January, 2023

405 Method Not Allowed - For Keyless entity types

Image
EF Core model allows keyless entity types, which can be used to carry out database queries against data that doesn't contain key values. There are never tracked for changes in the DataBase Context and therefore are never inserted, updated or deleted on the database. How to use this in your class. Let's say, you have a class named Share, you can place [Keyless] attributes on top of the class, and that's it! using Microsoft.EntityFrameworkCore; using System.ComponentModel; using System.ComponentModel.DataAnnotations; namespace AzureHostedApi {     [Keyless]     public class Share     {         [DisplayName("Share Code")]         [Required(ErrorMessage = "{0} is required")]         [StringLength(10, MinimumLength = 3,         ErrorMessage = "Share Code should be minimum 3 characters and a maximum of 10 characters")]         [DataType(DataType.Text)]         public string? ShareCode { get; set; }                [DisplayName("Share Name")

.NET WebAPI calling Mongo DB

Image
 This is basic WebAPI project created using .NET 7.0 version and it makes call to MongoDB database collection sitting in Mongo Cloud. The DB configuration is in appsettings.json file. Below is the project structure - simple is the best :) You can create simple WebApI project using VS Studio 2022 on .NET 7.0 and then replace the code of individual pages from below. Please create the folders i.e. Models , Controller , and Services as shows in above picture  Please make sure to update DB configuration in appsettings.json according to your setup. The other important thing is to install MongoDB Driver, Core etc from Nuget Package. Page: AppSettings.json {   "MovieStoreDatabase": {     "ConnectionString": "mongodb+srv://m001-stu01-monb-basics@box.hongodb.net/test",     "DatabaseName": "video",     "DBCollectionName": "movieDetails"   },   "Logging": {     "LogLevel": {       "Default": "