Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity Framework Support #112

Open
harrypooni-118 opened this issue Jul 23, 2024 · 3 comments
Open

Entity Framework Support #112

harrypooni-118 opened this issue Jul 23, 2024 · 3 comments
Assignees

Comments

@harrypooni-118
Copy link

Will there be support for EF Core with DynamoDb to utilise LINQ expression when querying tables and take advantage of EF Core. MongoDB and CosmosDB is fully supported in EF Core, DynamoDB is the only one left out.

@tebanieo
Copy link
Contributor

Hello Harry, thanks for creating this issue, natively does not provide any ORM, at this point. Having said that I will create a Product Feature Request in your behalf. Please provide additional information about your use case, the necessity for this, and the implications of lacking native support. I intend to keep the issue open in order to collect as much information as possible, which will let me give feedback to the service team.

@tebanieo tebanieo self-assigned this Jul 23, 2024
@harrypooni-118
Copy link
Author

Thanks @tebanieo
Some of the key features is configuring the mapping between the POCO Properties, querying data via a LINQ expression and support for transactions. I know DynamoDB can perform these requests outside of EF Core using the SDK, however the LINQ expression to query data is on the missing key components to provide a better developer experience.

These capabilities can extend other libraries such MassTransit for outbox pattern integration. At the moment almost all devs have to use 2 separate data sources to use the MassTransit outbox pattern when coupled with DynamodDB, due to no EF Core support.

@harrypooni-118
Copy link
Author

harrypooni-118 commented Aug 17, 2024

Here is an example config that EF Core offers to simply the integration with data sources. These example below highlights how to configure the dbcontext and configure the entity you want to set within the context. This has come from a RD database, but the principal is the same. More than happy to assist with a nosql equivalent. There is a few examples for MongoDb on the web.

public class OrderDbContext: DbContext
{
    public OrderDbContext(DbContextOptions<OrderDbContext> options) : base(options)
    {
    }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder
            .UseInMemoryDatabase(Guid.NewGuid().ToString()); // SameName = Shared in memory database across all unit tests  
    }

    public DbSet<Order> Orders { get; set; } = null!;
    public DbSet<OrderLine> OrderLines { get; set; } = null!;

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.ApplyConfiguration(new OrderMapConfig());
    }
}

public class OrderMapConfig : IEntityTypeConfiguration<Order>
{
    public void Configure(EntityTypeBuilder<Order> builder)
    {
        builder.ToTable("Orders");
        builder.HasKey(_ => _.Id);
        builder.OwnsMany(_ => _.OrderLines, sb =>
        {
            sb.HasKey(_ => _.Id);
            sb.Property(_ => _.Id).ValueGeneratedOnAdd().UsePropertyAccessMode(PropertyAccessMode.Property);
            sb.Property(_ => _.OrderId).UsePropertyAccessMode(PropertyAccessMode.Property);
            sb.WithOwner().HasForeignKey(_ => _.OrderId);
            sb.ToTable("OrderLines");
        });
        builder.Property(_ => _.Id).ValueGeneratedOnAdd();
        builder.Property(_ => _.OrgId).UsePropertyAccessMode(PropertyAccessMode.Property);
        builder.Property(_ => _.OrgUnit).UsePropertyAccessMode(PropertyAccessMode.Property);
        builder.Navigation(_ => _.OrderLines).AutoInclude().UsePropertyAccessMode(PropertyAccessMode.Property);
        builder.Property(_ => _.CreatedAt).UsePropertyAccessMode(PropertyAccessMode.Property);
        builder.Property(_ => _.UpdatedAt).UsePropertyAccessMode(PropertyAccessMode.Property);
        builder.Ignore(_ => _.DomainEvents);
    }
}

@tebanieo tebanieo added help wanted We are welcoming your contribution :) and removed help wanted We are welcoming your contribution :) labels Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants