Simply.Property 0.1.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Simply.Property --version 0.1.2
NuGet\Install-Package Simply.Property -Version 0.1.2
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="Simply.Property" Version="0.1.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Simply.Property --version 0.1.2
#r "nuget: Simply.Property, 0.1.2"
#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.
// Install Simply.Property as a Cake Addin
#addin nuget:?package=Simply.Property&version=0.1.2

// Install Simply.Property as a Cake Tool
#tool nuget:?package=Simply.Property&version=0.1.2

NuGet installation

Install the Simply.Property NuGet package:

PM> Install-Package Simply.Property

The Install-Package Simply.Property is required since NuGet always defaults to the oldest, and most buggy, version of any dependency.

Step #1. Implement interface IRepository, Repository and RepositoryFactory

public class Repository<T> : IRepository where T : DbContext
{
    protected T ctx;
    public Repository(T context) { ctx = context; ctx.Database.SetCommandTimeout(300); }
    public Task<int> ExecuteSqlAsync(string query) => ctx.Database.ExecuteSqlCommandAsync(query);
    public Task<int> ExecuteSqlWithJsonAsync(string query, string json) => ctx.Database.ExecuteSqlCommandAsync(query, new SqlParameter("@json", json));
    public Task<int> ExecuteSqlAsync(RepositorySqlQuery query) => (query.Json != null) ? ExecuteSqlWithJsonAsync(query.Query, query.Json) : ExecuteSqlAsync(query.Query);
    public async Task ExecuteSqlWithTransactionAsync(IEnumerable<RepositorySqlQuery> queries)
    {
        using (var transaction = await ctx.Database.BeginTransactionAsync().ConfigureAwait(false))
        {
            try
            {
                foreach (var query in queries)
                    await ExecuteSqlAsync(query).ConfigureAwait(false);
                transaction.Commit();
            }
            catch(SqlException)
            {
                transaction.Rollback();
            }
        }
    }
    public Task<List<TEntity>> GetAsync<TEntity>() where TEntity : class => ctx.Set<TEntity>().AsNoTracking().ToListAsync();
    public Task<int> AddAsync<TEntity>(TEntity entity) where TEntity : class
    {
        ctx.Add(entity);
        return SaveAsync();
    }
    public Task<int> AddManyAsync<TEntity>(IEnumerable<TEntity> entities) where TEntity : class
    {
        foreach (var entity in entities)
            ctx.Add(entity);
        return SaveAsync();
    }
    public Task<int> SaveAsync() => ctx.SaveChangesAsync();
    public void Dispose() => ctx.Dispose();
}

public class SampleRepository : Repository<SampleDbContext>, ISampleRepository
{
    public SampleRepository(SampleDbContext context) : base(context)
	{ 
	}
	
	// Here you code to access Database
}

public class SampleRepositoryFactory : RepositoryFactory, ISampleRepositoryFactory
{
    public SampleRepositoryFactory(IQueryScope queryScope) : base(queryScope)
	{ 
	}
    public ISampleRepository GetSampleRepository() => new SampleRepository(new SampleDbContext());
    public override IRepository GetRepository() => GetSampleRepository();
}

Step #2. Data annotation

[Table("OStatementBabyFile")]
[Schema("BABIES", "tempId")]
public class StatementBabyFileOriginalObject
{
    public StatementBabyFileOriginalObject()
    {
        RowCreated = DateTime.UtcNow;
    }
    [Required, Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public long Id { get; set; }
    public Guid tempId { get; set; }
    [XmlProperty("NRECORDS")]
    public int RowCount { get; set; }
    [XmlProperty("SMOCOD")]
    [MaxLength(10)]
    public string Smo { get; set; }
    [XmlProperty("FILENAME")]
    [MaxLength(50)]
    public string Name { get; set; }
    [XmlProperty("VERS")]
    [MaxLength(10)]
    public string Version { get; set; }
    public DateTime? RowCreated { get; set; }
}

[Table("OStatementBabyEntry")]
[Schema("BABY", "tempId", "BABIES", "upperId")]
public class StatementBabyEntryOriginalObject
{
    [Required, Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public long Id { get; set; }
    public Guid tempId { get; set; }
    public Guid upperId { get; set; }

    [MaxLength(50)]
    [XmlProperty("FAM")]
    public string LastName { get; set; }
    [MaxLength(50)]
    [XmlProperty("IM")]
    public string FirstName { get; set; }
    [MaxLength(50)]
    [XmlProperty("OT")]
    public string MiddleName { get; set; }
    [XmlProperty("W")]
    public long? SexId { get; set; }
    [XmlProperty("DR")]
    public DateTime? Birthday { get; set; }
    [XmlProperty("MR")]
    [MaxLength(500)]
    public string PlaceOfBirth { get; set; }
}

[Table("OStatementBabyDocument")]
[Schema("DOC", "tempId", "BABY", "upperId")]
public class StatementBabyDocumentOriginalObject
{
    [Required, Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public long Id { get; set; }
    public Guid tempId { get; set; }
    public Guid upperId { get; set; }

    [XmlProperty("DOCTYPE")]
    public int? DocumentId { get; set; }
    [XmlProperty("DOCSER")]
    [MaxLength(50)]
    public string DocumentSerial { get; set; }
    [XmlProperty("DOCNUM")]
    [MaxLength(50)]
    public string DocumentNumber { get; set; }
    [XmlProperty("NAME_VP")]
    [MaxLength(500)]
    public string WhoIssue { get; set; }
    [XmlProperty("DOCDATE")]
    public DateTime? DocumentIssue { get; set; }
}

Step #3. Create and execute Sql queries

// Create repository factory
IPropertyScope propertyScope = new PropertyScope();
IQueryScope queryScope = new QueryScope(propertyScope);
using (ISampleRepositoryFactory repositoryFactory = new SampleRepositoryFactory(queryScope))
{
	// Create entities
	var fileList = new List<StatementBabyFileOriginalObject>()
	{
		new StatementBabyFileOriginalObject() { Name = "Sample1", Version = "1.0", RowCount = 3, RowCreated = DateTime.UtcNow }
	};
	var entryList = new List<StatementBabyEntryOriginalObject>()
	{
		new StatementBabyEntryOriginalObject() { LastName = "Иванов", FirstName = "Иван", MiddleName = "Иванович", Birthday = new DateTime(1990, 1, 1), SexId = 1 },
		new StatementBabyEntryOriginalObject() { LastName = "Петров", FirstName = "Иван", MiddleName = "Иванович", Birthday = new DateTime(1991, 1, 1), SexId = 1 },
		new StatementBabyEntryOriginalObject() { LastName = "Иванова", FirstName = "Светлана", MiddleName = "Ивановна", Birthday = new DateTime(1992, 1, 1), SexId = 2 }
	};

	// Create table in database and insert data
	await repositoryFactory.ExecuteSqlWithTransactionAsync(
		repositoryFactory.CreateTableToSql<StatementBabyFileOriginalObject>(),
		repositoryFactory.CreateTableToSql<StatementBabyEntryOriginalObject>(),
		repositoryFactory.AddToSql(fileList),
		repositoryFactory.AddToSql(entryList)
	);
}

Step #4. Xml file reader


using (var objectReader = new ObjectReader(scope))
{
	objectReader
		.handle<StatementBabyFileOriginalObject>(entities => repositoryFactory.BulkAddAsync(entities))
		.handle<StatementBabyEntryOriginalObject>(entities => repositoryFactory.BulkAddAsync(entities));
    objectReader.getObject(fileName);
}

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp3.0 is compatible.  netcoreapp3.1 was computed. 
.NET Framework net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Simply.Property:

Package Downloads
Simply.Property.SqlServer

This library build bulk sql command in single query.

Simply.Property.XmlReader

This library performs xml to json conversion

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.3.12 1,088 4/12/2020
0.3.11 673 4/12/2020
0.3.10 478 12/2/2019
0.3.9 1,066 11/15/2019
0.3.8 666 11/15/2019
0.3.7 680 11/7/2019
0.3.6 882 10/25/2019
0.3.5 764 10/24/2019
0.3.4 478 10/24/2019
0.3.3 470 10/24/2019
0.3.2 467 10/24/2019
0.3.1 470 10/23/2019
0.3.0 464 10/22/2019
0.2.7 475 10/21/2019
0.2.6 493 10/21/2019
0.2.5 469 10/20/2019
0.2.4 487 10/18/2019
0.2.3 492 10/17/2019
0.2.2 504 10/17/2019
0.2.1 487 10/16/2019
0.2.0 461 10/16/2019
0.1.9 486 10/16/2019
0.1.8 495 10/16/2019
0.1.7 512 10/14/2019
0.1.6 498 10/14/2019
0.1.5 497 10/13/2019
0.1.4 483 9/27/2019
0.1.3 504 9/23/2019
0.1.2 496 9/23/2019
0.1.1 525 9/19/2019
0.1.0 490 9/19/2019