DataGenerator.EntityFramework.Core 1.0.3

dotnet add package DataGenerator.EntityFramework.Core --version 1.0.3
                    
NuGet\Install-Package DataGenerator.EntityFramework.Core -Version 1.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DataGenerator.EntityFramework.Core" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DataGenerator.EntityFramework.Core" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="DataGenerator.EntityFramework.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DataGenerator.EntityFramework.Core --version 1.0.3
                    
#r "nuget: DataGenerator.EntityFramework.Core, 1.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DataGenerator.EntityFramework.Core@1.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DataGenerator.EntityFramework.Core&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=DataGenerator.EntityFramework.Core&version=1.0.3
                    
Install as a Cake Tool

Nuget

Introduction

DataGenerator.EntityFramework.Core is a package to generate Mock Data using OpenAI & EntityFramework Core on Windows / Linux / MacOS. The package is compatible only with primitive DataTypes, Complex DataTypes are not supported.

Parameter: openAiBatchSize

openAiBatchSize should be equal to noOfRows in case you want to ensure unique data values.

Parameter: inDataValue

inDataValue is the value of the data under which you want to generate data. For instance under state Maharashtra you want to generate data for table City then pass inDataValue as maharashtra.

Getting started

From nuget packages

Nuget

PM> Install-Package DataGenerator.EntityFramework.Core

Usage

using DataGenerator.EntityFrameworkCore.Interfaces;
    
public class ConsoleTraceWriter : ITraceWriter
{
    public void Log(string message)
    {
        Console.WriteLine(message);
    }

    public void Verbose(string message)
    {
        Console.WriteLine(message);
    }
}
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Diagnostics;
using System.Collections.Generic;
using DataGenerator.EntityFrameworkCore.Mock.Data.Generators;
using DataGenerator.EntityFrameworkCore.Data.Generators;
using System.Globalization;

Random random = new Random();
var connStr = Environment.GetEnvironmentVariable("LOCALHOST_MYSQL")!;
var dbOptions = new DbContextOptionsBuilder<Context>().UseMySql(connStr, ServerVersion.AutoDetect(connStr),
                    mySqlOptionsAction: (MySqlDbContextOptionsBuilder sqlOptions) =>
                    {
                        sqlOptions.EnableRetryOnFailure(
                        maxRetryCount: 10,
                        maxRetryDelay: TimeSpan.FromSeconds(30),
                        errorNumbersToAdd: null);
                        sqlOptions.CommandTimeout(240);
                    }).ConfigureWarnings(w => w.Throw(RelationalEventId.MultipleCollectionIncludeWarning)).Options;
var context = new Context(dbOptions);
var trace = new ConsoleTraceWriter();
var openAiApiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
string locale = CultureInfo.CurrentCulture.Name;

try
{
    MockDataGenerator mockDataGenerator = new MockDataGenerator(trace, openAiApiKey);
    EntityFrameworkDataGenerator<Context> entityFrameworkDataGenerator = new EntityFrameworkDataGenerator<Context>(context, mockDataGenerator, trace);

    var users = await entityFrameworkDataGenerator.GenerateData<User>(locale, 5, 5);

    context.Users.AddRange(users!);

    var schools = await entityFrameworkDataGenerator.GenerateData<School>(locale, 1, 1);

    foreach (var school in schools!)
    {
        school.CreatedBy = users?[random.Next(0, users.Count() - 1)];
        school.UpdatedBy = users?[random.Next(0, users.Count() - 1)];
    }

    context.Schools.AddRange(schools!);

    await context.SaveChangesAsync();
}
catch (Exception ex)
{
    trace.Log(ex.Message);
}

Third Parties

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.3 156 2/28/2025
1.0.2 131 2/28/2025
1.0.1 130 2/28/2025
1.0.0 141 2/28/2025