ADO.NET Provider for WooCommerce

Build 20.0.7587

Code-First Approach

An alternative to introspecting the model from the provider is to handwrite your model classes. This is the code-first approach to Entity Framework, which gives you greater control over the exact data model you use in your application.

Create the Context Class

This is the base object that extends DbContext and exposes the DbSet properties that represent the tables in the data source. Override some of the default functionality of the DbContext class by overriding the OnConfiguring method.

using Microsoft.EntityFrameworkCore;

public class WooCommerceContext : DbContext
{
	public DbSet<Orders> Orders { get; set; }

	protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
	{
		if (!optionsBuilder.IsConfigured)
		{
			optionsBuilder.UseWooCommerce(" Url=http://localhost/wordpress/;ConsumerKey=ck_ec52c76185c088ecaa3145287c8acba55a6f59ad;ConsumerSecret=cs_9fde14bf57126156701a7563fc87575713c355e5;");
		}
	}
}

Create the Table Models

Define a class for each table that was defined in the DbSet properties of the context class. The table classes should have a list of properties that correspond to each field of that table. A corresponding map class must be defined to configure attributes for each property in the table class.

public class Orders
{
	public string Id { get; set; }
	public string Total { get; set; }
}

Copyright (c) 2020 CData Software, Inc. - All rights reserved.
Build 20.0.7587