DataGenerator.EntityFramework.Core
1.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package DataGenerator.EntityFramework.Core --version 1.0.0
NuGet\Install-Package DataGenerator.EntityFramework.Core -Version 1.0.0
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.0" />
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.0" />
<PackageReference Include="DataGenerator.EntityFramework.Core" />
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.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DataGenerator.EntityFramework.Core, 1.0.0"
#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.0
#: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.0
#tool nuget:?package=DataGenerator.EntityFramework.Core&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Introduction
DataGenerator.EntityFramework.Core is a package to generate Mock Data using OpenAI & EntityFramework Core on Windows / Linux / MacOS.
Getting started
From nuget packages
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())];
school.UpdatedBy = users?[random.Next(0, users.Count())];
}
context.Schools.AddRange(schools!);
var schoolBranches = await entityFrameworkDataGenerator.GenerateData<SchoolBranch>(locale, 5, 5, schools?[0].SchoolName!);
foreach (var schoolBranch in schoolBranches!)
{
schoolBranch.School = schools?[0];
schoolBranch.CreatedBy = users?[random.Next(0, users.Count())];
schoolBranch.UpdatedBy = users?[random.Next(0, users.Count())];
}
context.SchoolBranches.AddRange(schoolBranches!);
var countries = await entityFrameworkDataGenerator.GenerateData<Country>(locale, 1, 1);
foreach (var country in countries!)
{
country.SchoolBranch = schoolBranches?[random.Next(0, schoolBranches.Count())];
country.CreatedBy = users?[random.Next(0, users.Count())];
country.UpdatedBy = users?[random.Next(0, users.Count())];
}
context.Countries.AddRange(countries!);
var states = await entityFrameworkDataGenerator.GenerateData<State>(locale, 25, 25);
foreach (var state in states!)
{
state.Country = countries?[0];
state.CreatedBy = users?[random.Next(0, users.Count())];
state.UpdatedBy = users?[random.Next(0, users.Count())];
}
context.States.AddRange(states!);
var cities = new List<City>();
foreach (var state in states!)
{
var citiesInState = await entityFrameworkDataGenerator.GenerateData<City>(locale, 25, 25, state.Name!);
citiesInState?.ForEach((city) =>
{
city.StateId = state.StateId;
city.CreatedBy = users?[random.Next(0, users.Count())];
city.UpdatedBy = users?[random.Next(0, users.Count())];
});
cities.AddRange(citiesInState!);
}
context.Cities.AddRange(cities!);
var addressTypes = await entityFrameworkDataGenerator.GenerateData<AddressType>(locale, 2, 2);
foreach (var addressType in addressTypes!)
{
addressType.SchoolBranch = schoolBranches?[random.Next(0, schoolBranches.Count())];
addressType.CreatedBy = users?[random.Next(0, users.Count())];
addressType.UpdatedBy = users?[random.Next(0, users.Count())];
}
context.AddressTypes.AddRange(addressTypes!);
var addresses = new List<Address>();
foreach (var city in cities!)
{
var addressesInCity = await entityFrameworkDataGenerator.GenerateData<Address>(locale, 125, 125, city.Name!);
foreach (var address in addressesInCity!)
{
address.AddressType = addressTypes?[random.Next(0, addressTypes.Count())];
address.City = city;
address.CreatedBy = users?[random.Next(0, users.Count())];
address.UpdatedBy = users?[random.Next(0, users.Count())];
}
addresses.AddRange(addressesInCity);
}
context.Addresses.AddRange(addresses!);
await context.SaveChangesAsync();
}
catch (Exception ex)
{
trace.Log(ex.Message);
}
Third Parties
| Product | Versions 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.
-
net8.0
- Microsoft.EntityFrameworkCore (>= 8.0.12)
- OpenAI (>= 2.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.