my problem is I am unable to create custom tables in database through my plugin code
i am using latest nopCommerce version 4.40
here is what i have done
Domains Folder created classs PackagingBoxesRecords.cs
public partial class PackagingBoxesRecords : BaseEntity
{
//primary key
public int BoxID { get; set; }
//category id -- not a foregin key
public int CategoryID { get; set; }
public string BoxName { get; set; }
public string BoxDetails { get; set; }
public int Height { get; set; }
public int Width { get; set; }
public int Length { get; set; }
public DateTime AddedDateTime { get; set; }
}
In Data folder created class PackagingBoxesRecordBuilder.cs
public class PackagingBoxesRecordBuilder : NopEntityBuilder<PackagingBoxesRecords>
{
public override void MapEntity(CreateTableExpressionBuilder table)
{
table
//map the primary key (not necessary if it is Id field)
.WithColumn(nameof(PackagingBoxesRecords.BoxID)).AsInt32().PrimaryKey()
.WithColumn(nameof(PackagingBoxesRecords.CategoryID))
.AsInt32()
.Nullable()
.WithColumn(nameof(PackagingBoxesRecords.BoxName))
.AsString(1000)
.WithColumn(nameof(PackagingBoxesRecords.BoxDetails))
.AsString(1000)
.Nullable()
.WithColumn(nameof(PackagingBoxesRecords.Height))
.AsInt32()
.WithColumn(nameof(PackagingBoxesRecords.Width))
.AsInt32()
.WithColumn(nameof(PackagingBoxesRecords.Length))
.AsInt32()
.WithColumn(nameof(PackagingBoxesRecords.AddedDateTime))
.AsDateTime();
}
}
In Data folder anther class SchemaMigration.cs
[SkipMigrationOnUpdate]
[NopMigration("2021/11/26 12:20:55:1687541", "Packaging.Boxes base schema")]
public class SchemaMigration : AutoReversingMigration
{
protected IMigrationManager _migrationManager;
public SchemaMigration(IMigrationManager migrationManager)
{
_migrationManager = migrationManager;
}
public override void Up()
{
_migrationManager.BuildTable<PackagingBoxesRecords>(Create);
}
}
In Services Folder created interface IPackagingBoxesServices.cs
public interface IPackagingBoxesServices
{
public interface IProductViewTrackerService
{
/// <summary>
/// Logs the specified record.
/// </summary>
/// <param name="record">The record.</param>
void Log(PackagingBoxesRecords record);
}
}
In Services Folder created interface PackagingBoxesServices.cs
public class PackagingBoxesServices : IPackagingBoxesServices
{
private readonly IRepository<PackagingBoxesRecords> _packagingBoxesRecordsRepository;
public PackagingBoxesServices(IRepository<PackagingBoxesRecords> packagingBoxesRecordsRepository)
{
_packagingBoxesRecordsRepository = packagingBoxesRecordsRepository;
}
/// <summary>
/// Logs the specified record.
/// </summary>
/// <param name="record">The record.</param>
public virtual void Log(PackagingBoxesRecords record)
{
if (record == null)
throw new ArgumentNullException(nameof(record));
_packagingBoxesRecordsRepository.Insert(record);
}
}
In Infrastructure folder created Dependency Injection class DependencyRegistrar.cs
public class DependencyRegistrar : IDependencyRegistrar
{
/// <summary>
/// Register services and interfaces
/// </summary>
/// <param name="services">Collection of service descriptors</param>
/// <param name="typeFinder">Type finder</param>
/// <param name="appSettings">App settings</param>
public virtual void Register(IServiceCollection services, ITypeFinder typeFinder, AppSettings appSettings)
{
services.AddScoped<IPackagingBoxesServices, PackagingBoxesServices>();
}
/// <summary>
/// Order of this dependency registrar implementation
/// </summary>
public int Order => 1;
}
Here is my code please identify where i am going wrong