Hello All
If you are getting below in api
If you are getting below in api
public class Order
{
public int OrderId { get; set; }
}
public class Customer
{
public int CustomerId { get; set; }
public string CustomerName { get; set; }
}
public class Order
{
public int OrderId { get; set; }
public Customer Customer { get; set; }
}
public class Customer
{
public int CustomerId { get; set; }
public string CustomerName { get; set; }
}
public class Order
{
public int OrderId { get; set; }
}
public class Customer
{
public int CustomerId { get; set; }
public string CustomerName { get; set; }
public ICollection<Order> Orders { get; set; }
}
ICollection<Order>. This also results in a one-to-many relationship between the Order and Customer entities. AS You Want". ASP.NET Web Application, we have multiple sub-options, i.e., Empty, Internet Application, Web API, etc.Product class:public class Product
{
public int ProductID { get; set; }
public string ProductName { get; set; }
public string ProductCategory { get; set; }
public int Price { get; set; }
}
Controller class plays an important role, because request coming from client hits the controller first. Then the controller decides which model to use to serve the incoming request. So, in order to add a controller:ProductsController".
public class ProductsController : ApiController
{
Product[] products = new Product[]
{
new Product { ProductID = 1, ProductName = "Product 1",
ProductCategory= "Category 1", Price = 120 },
new Product { ProductID = 2, ProductName = "Product 2",
ProductCategory= "Category 1", Price = 100 },
new Product { ProductID = 3, ProductName = "Product 3",
ProductCategory= "Category 2", Price = 150 },
new Product { ProductID = 4, ProductName = "Product 4",
ProductCategory= "Category 3", Price = 90 }
};
public IEnumerable<Product> GetProducts()
{
return products;
}
}
using FirstWebAPIService.Models;" at the top of the controller class.Product controller, change the URL as "http://localhost:XXXX/api/products". You will see the results as shown in the following output window.http://localhost:28483/swagger/ui/index, it generates this error:500 : undefined http://localhost:28483/swagger/docs/v1
Solution:-App_Start\SwaggerConfig.cs file and under EnableSwagger lambda expression add this line:c.SchemaId(x => x.FullName);
Full code is like this:
GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
// your configs...
c.SchemaId(x => x.FullName);
// other configs...
})
.EnableSwaggerUi(c =>
// ....
});
Using this i thing problem will be resolve
Thank you.
using System; public class ParentClass { public ParentClass() { Console.WriteLine("Parent Constructor."); } public void print() { Console.WriteLine("I'm a Parent Class."); } } public class ChildClass : ParentClass { public ChildClass() { Console.WriteLine("Child Constructor."); } public static void Main() { ChildClass child = new ChildClass(); child.print(); } }
Output:
Parent Constructor. Child Constructor. I'm a Parent Class.Thank youShows two classes. The top class is named ParentClass and the main class is called ChildClass. What we want to do is create a child class, using existing code from ParentClass.First we must declare our intention to use ParentClass as the base class of ChildClass. This is accomplished through the ChildClassdeclaration public class ChildClass : ParentClass. The base class is specified by adding a colon, “:”, after the derived class identifier and then specifying the base class name.Note: C# supports single class inheritance only. Therefore, you can specify only one base class to inherit from. However, it does allow multiple interface inheritance, a subject covered in a later lesson.ChildClass has exactly the same capabilities as ParentClass. Because of this, you can also say ChildClass “is” a ParentClass. This is shown in the Main() method of ChildClass when the print() method is called. ChildClass does not have its own print() method, so it uses theParentClass print() method. You can see the results in the 3rd line of output.Base classes are automatically instantiated before derived classes. Notice the output from Listing . The ParentClass constructor executed before the ChildClass constructor.