Comments (2)
public class PaymentTerm : Entity, IAggregateRoot
{
public PaymentTerm(short payTermCode, string payTermName, short instNum, bool active, List paymentTermInstallmentLayouts)
{
PayTermCode = payTermCode;
PayTermName = payTermName;
InstNum = instNum;
Active = active;
_paymentTermInstallmentLayouts = paymentTermInstallmentLayouts;
}
//Construtor vazio para o EF Core
public PaymentTerm() { }
/// <summary>
/// Código da condição de pagamento
/// </summary>
public short PayTermCode { get; set; }
/// <summary>
/// Descrição da condição de pagamento
/// </summary>
public string PayTermName { get; set; }
/// <summary>
/// Parcelas totais
/// </summary>
public short InstNum { get; set; }
/// <summary>
/// Ativa
/// </summary>
public bool Active { get; set; }
/// <summary>
///
/// </summary>
private readonly List<PaymentTermInstallmentLayout> _paymentTermInstallmentLayouts = new List<PaymentTermInstallmentLayout>();
/// <summary>
///
/// </summary>
public IReadOnlyCollection<PaymentTermInstallmentLayout> PaymentTermInstallmentLayouts => _paymentTermInstallmentLayouts.AsReadOnly();
}
public class PaymentTermInstallmentLayout
{
public PaymentTermInstallmentLayout(short payTermCode, short intsNo, short instMonth, short instDays, decimal instPrcnt)
{
PayTermCode = payTermCode;
IntsNo = intsNo;
InstMonth = instMonth;
InstDays = instDays;
InstPrcnt = instPrcnt;
}
//Construtor vazio para o EF Core
public PaymentTermInstallmentLayout() { }
/// <summary>
/// Código da codição de pagamento
/// </summary>
public short PayTermCode { get; set; }
/// <summary>
/// N° da parcela
/// </summary>
public short IntsNo { get; set; }
/// <summary>
/// Meses a contar da data do documento
/// </summary>
public short InstMonth { get; set; }
/// <summary>
/// Dias a conta da data do documento
/// </summary>
public short InstDays { get; set; }
/// <summary>
/// Percentual da parcela
/// </summary>
public decimal InstPrcnt { get; set; }
}
public class PaymentTermMap : IEntityTypeConfiguration
{
public void Configure(EntityTypeBuilder builder)
{
builder.ToTable("PaymentTerms");
builder.Ignore(p => p.Id);
builder.Property(p => p.PayTermCode)
.HasColumnType("smallint")
.HasColumnName("PayTermCode")
.ValueGeneratedNever()
.IsRequired();
builder.Property(p => p.PayTermName)
.HasColumnType("nvarchar(100)")
.HasColumnName("PayTermName")
.HasMaxLength(100)
.IsRequired();
builder.Property(p => p.Active)
.HasColumnType("bit")
.HasColumnName("Active")
.IsRequired();
builder.Property(p => p.InstNum)
.HasColumnType("smallint")
.HasColumnName("InstNum")
.IsRequired();
builder.HasKey(p => p.PayTermCode);
builder.HasMany(p => p.PaymentTermInstallmentLayouts)
.WithOne()
.HasForeignKey(p => p.PayTermCode)
.Metadata.PrincipalToDependent.SetPropertyAccessMode(PropertyAccessMode.Field);
}
}
public class PaymentTermInstallmentLayoutMap : IEntityTypeConfiguration
{
public void Configure(EntityTypeBuilder builder)
{
builder.Property(p => p.PayTermCode)
.HasColumnType("smallint")
.HasColumnName("PayTermCode")
.ValueGeneratedNever()
.IsRequired();
builder.Property(p => p.IntsNo)
.HasColumnType("smallint")
.HasColumnName("IntsNo")
.ValueGeneratedNever()
.IsRequired();
builder.Property(p => p.InstMonth)
.HasColumnType("smallint")
.HasColumnName("InstMonth")
.IsRequired();
builder.Property(p => p.InstDays)
.HasColumnType("smallint")
.HasColumnName("InstDays")
.IsRequired();
builder.Property(p => p.InstPrcnt)
.HasColumnType("numeric(19,6)")
.HasColumnName("InstPrcnt")
.HasPrecision(19, 6)
.IsRequired();
builder.HasKey(p => new { p.PayTermCode, p.IntsNo });
}
}
public class PaymentTermRepository : IPaymentTermRepository
{
protected readonly HammerSysContext Db;
protected readonly DbSet DbSet;
public PaymentTermRepository(HammerSysContext context)
{
Db = context;
DbSet = Db.Set<PaymentTerm>();
}
public IUnitOfWork UnitOfWork => Db;
public async Task<PaymentTerm> GetByKey(short payTermCode)
{
return await DbSet.Include(p => p.PaymentTermInstallmentLayouts)
.FirstAsync(w => w.PayTermCode == payTermCode);
}
public void Add(PaymentTerm paymentTerm)
{
DbSet.Add(paymentTerm);
}
public void Update(PaymentTerm paymentTerm)
{
DbSet.Update(paymentTerm);
}
public void Remove(PaymentTerm paymentTerm)
{
DbSet.Remove(paymentTerm);
}
public void Dispose()
{
Db.Dispose();
}
}
from equinoxproject.
@victorlpb92, DDD não diz "como deve ser feito", mas sim "o que deve ser feito", ele é livre de tecnologias, frameworks e detalhes técnicos.
DDD diz que cada agregado deve ter apenas um único repositório para todas as suas entidades, mas não diz que tecnologia ou framework você vai utilizar, ou como você vai fazer tecnicamente. Exemplo:
Se você tiver duas entidades em um agregado, NotaFiscal (raíz do agregado) e NotaFiscalItem, você vai ter apenas o repositório da raíz do agregado NotaFiscalRepository. Através desse repositório que você vai gerenciar todas as entidades do agregado.
Você que vai decidir qual a melhor lógica interna de cada método:
public interface INotaFiscalRepository
{
/// 1) Dá pra inserir a nota fiscal com os itens direto pelo Entity Framework
// context.NotasFiscais.Add(notaFiscal); // Se o EF estiver bem configurado vai funcionar
/// 2) Dá pra inserir a nota fiscal e depois os itens com o AddRange (menos performático que o anterior)
// context.NotasFiscais.Add(notaFiscal);
// context.NotasFiscaisItens.AddRange(notaFiscal.Itens);
/// 3) Dá pra inserir a nota fiscal e depois cada item usando um for (pouco performático)
// context.NotasFiscais.Add(notaFiscal);
// foreach(var item in notaFiscal.Itens)
// {
// context.NotasFiscaisItens.Add(item);
// }
void Adicionar(NotaFiscal notaFiscal);
/// Aqui você consegue fazer qualquer lógica também, você que vai decidir a melhor e mais performática
void Atualizar(NotaFiscal notaFiscal);
NotaFiscal Obter(NotaFiscalId notaFiscalId);
IEnumerable<NotaFiscal> Listar();
void Excluir(NotaFiscalItemId notaFiscalItemId);
}
Portanto a sua dúvida não tem relação com DDD, mas sim com Entity Framework. Verifique os links abaixo para tentar resolver:
https://stackoverflow.com/questions/27176014/how-to-add-update-child-entities-when-updating-a-parent-entity-in-ef
https://stackoverflow.com/questions/33056482/is-it-really-impossible-to-update-child-collection-in-ef-out-of-the-box-aka-non
https://stackoverflow.com/questions/25831959/how-to-update-child-list-in-entity-framework
from equinoxproject.
Related Issues (20)
- 为什么只有事件保存,没有事件查询,希望通过DynamicApiControllerInfo根据Serivce 自动生成WebAPI HOT 1
- hello,where is identity context? How to use
- Exempt de Azure Function com DI HOT 2
- Some services are not able to be constructed (Error while validating the service descriptor) HOT 2
- Essa arquitetura CQRS + ES ainda é considerada válida? HOT 3
- Need migration commands to start with the projects HOT 1
- Api generating an invalid JTW signature HOT 1
- Customizar IdentityUser HOT 1
- Ajuda para teste Teste de unidade para o CommandHandler e assert do evento publicado HOT 1
- implement business rules involving multiple entities HOT 1
- When updating Identity Migration in the Equinox.UI.Web layer an error is appearing that the object of type ApplicationDbContext cannot be created HOT 8
- Relate in EquinoxContext AspNetUsers with Employee HOT 1
- Why is ApplicationDbContext.cs inside Equinox.UI.Web project? this is nonsense HOT 1
- customer history api non consistent with the name between API and Web project
- EquinoxProject is not sample of EventSourcing, but sample of audith log
- Doubt in migrations HOT 1
- update-database HOT 2
- Project still active? HOT 2
- Update DataBase HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from equinoxproject.