IXC.ORM 1.0.6

dotnet add package IXC.ORM --version 1.0.6
                    
NuGet\Install-Package IXC.ORM -Version 1.0.6
                    
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="IXC.ORM" Version="1.0.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="IXC.ORM" Version="1.0.6" />
                    
Directory.Packages.props
<PackageReference Include="IXC.ORM" />
                    
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 IXC.ORM --version 1.0.6
                    
#r "nuget: IXC.ORM, 1.0.6"
                    
#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 IXC.ORM@1.0.6
                    
#: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=IXC.ORM&version=1.0.6
                    
Install as a Cake Addin
#tool nuget:?package=IXC.ORM&version=1.0.6
                    
Install as a Cake Tool

Esse ORM foi criado com o intuito de facilitar o consumo de dados da API oficial do IXC Provedor.
Essa biblioteca não faz parte das bibliotecas oficiais da IXCsoft e foi desenvolvida de forma independente e sem fins lucrativos.

⬇️ Download

dotnet add package IXC.ORM

Após o download, certifique-se de que a dependência foi adicionada ao seu .csproj...

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    ...
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="IXC.ORM" Version="1.0.6" />
    ...
  </ItemGroup>
  ...

🖥️ Variáveis de Ambiente

No appsettings.json ou appsettings.Development.json.

{
  "IxcOrm": {
    "AccessToken": "token gerado dentro do IXC",
    "ServerDomain": "dominiodoseuixc.com.br"
  }
}

No docker-compose.yaml.

services:
  sua-aplicacao:
    build:
      context: .
      dockerfile: Dockerfile
    image: sua-imagem-docker:0.0.0
    environment:
      # Obtendo as variáveis a partir de um .env
      - IxcOrm__AccessToken=${IXC_ACCESS_TOKEN}
      - IxcOrm__ServerDomain=${IXC_SERVER_DOMAIN}
      ...

Siga o exemplo abaixo para carregar o ambiente da biblioteca em tempo de execução.

using DotNet.IXC.ORM.Config; // Sem isso, builder.Services.AddIxcOrmEnvironment(config => {}); não funciona!!!

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddIxcOrmEnvironment(config =>
{
    var accessToken = builder.Configuration.GetValue<string>("IxcOrm:AccessToken")
        ?? throw new InvalidOperationException("A variável IxcOrm:AccessToken não está configurada.");

    var serverDomain = builder.Configuration.GetValue<string>("IxcOrm:ServerDomain")
        ?? throw new InvalidOperationException("A variável IxcOrm:ServerDomain não está configurada.");

    config.SetupAccessToken(accessToken);
    config.SetupServerDomain(serverDomain);
});

👨‍💻 Implementação

Convertendo resultados com o auxílio da classe IxcRecord.

using DotNet.IXC.ORM;
using System.Text.Json.Serialization;

public class Cliente : IxcRecord
{
    [JsonPropertyName("razao")]
    public string Razao { get; set; } = string.Empty;

    [JsonPropertyName("cnpj_cpf")]
    public string CnpjCpf { get; set; } = string.Empty;
}

Utilizando a classe IxcOrm para poder enviar as requisições ao o seu IXC Provedor.

using DotNet.IXC.ORM;

public class ClienteOrm : IxcOrm
{
    public static ClienteOrm NewOrm()
    {
        return new ClienteOrm();
    }

    private ClienteOrm() : base("cliente") { } // Define a tabela "cliente" como alvo das consultas.

    public async Task<List<Cliente>?> FindByCnpjOrCpf(string cnpjOrCpf)
    {
        IxcOrmResponse<Cliente> response = await Where("cnpj_cpf")
            .Like(cnpjOrCpf)
            .GetAsync<Cliente>();

        if (response is null || response.Total == 0)
        {
            return null;
        }
        
        return response.Records;
    }
}

Ciar uma classe derivada de IxcOrm, como no exemplo acima, permitirá que você a utilize como no exemplo abaixo...

// EXEMPLO DE COMO IMPLEMENTAR UM POSSÍVEL MÉTODO "GET" EM UM CONTROLLER DA SUA API

[HttpGet("{cnpjOrCpf}")]
public async Task<IActionResult> FindByCnpjOrCpf([FromRoute] string cnpjOrCpf)
{
    using var orm = ClienteOrm.NewOrm();
    
    try
    {
        var clientes = await orm.FindByCnpjOrCpf(cnpjOrCpf);

        if (clientes is null)
        {
            return NotFound();
        }

        return Ok(clientes);
    }
    catch (IxcOrmResponseException e)
    {
        return Problem(detail: e.Message, statusCode: 500);
    }
    catch (IxcOrmRequestException e)
    {
        return Problem(detail: e.Message, statusCode: 400);
    }
}

Você não é obrigado a seguir à risca os exemplos acima... ☝🏻
Eles servem apenas como orientação sobre como utilizar esta biblioteca!

Contribuições

Contribuições são sempre bem-vindas!
Se você conhece uma maneira melhor de fazer algo, por favor, me avise!
Ou sinta-se a vontade para enviar um novo PR!

At.te,
<b>Felipe S. Carmo</b>.

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.6 89 5/2/2026
1.0.5 81 5/2/2026
1.0.4 88 5/2/2026
1.0.3 88 5/2/2026
1.0.2 91 5/2/2026
1.0.1 94 5/1/2026
1.0.0 86 5/1/2026