© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•7mo ago•
62 replies
Carlos Saraiva

✅ MongoDB Driver error when reading using interface

Hi guys, I'm having trouble trying to read from my mongodb database, I used to use one class, but now it is one interface and other classes that can have more properties than the interface.
public interface IEntity {
    public Guid Id { get; set; }
    public Guid? TenantId { get; set; }
}

public interface IAccount : IEntity
{
    public string Type { get; set; }
    public string Name { get; set; }
    public Currency Currency { get; set; }
    public DateTime CreatedAt { get; set; }
    public List<CurrencyBalance> CurrenciesBalance { get; set; }
    public DateTime? UpdatedAt { get; set; }
}

public class CreditCard : IAccount
{
    public Guid? AutomaticDebitAccountId { get; set; } = null;
    public required decimal Limit { get; set; }
    public override string Type { get; set; } = AccountType.CreditCard;
    public DateTime ClosingDate { get; set; }
    public DateTime ExpirationDate { get; set; }
}

public class DebitCard : IAccount
{
    public required override string Type { get; set; } = AccountType.Bank;
}
public interface IEntity {
    public Guid Id { get; set; }
    public Guid? TenantId { get; set; }
}

public interface IAccount : IEntity
{
    public string Type { get; set; }
    public string Name { get; set; }
    public Currency Currency { get; set; }
    public DateTime CreatedAt { get; set; }
    public List<CurrencyBalance> CurrenciesBalance { get; set; }
    public DateTime? UpdatedAt { get; set; }
}

public class CreditCard : IAccount
{
    public Guid? AutomaticDebitAccountId { get; set; } = null;
    public required decimal Limit { get; set; }
    public override string Type { get; set; } = AccountType.CreditCard;
    public DateTime ClosingDate { get; set; }
    public DateTime ExpirationDate { get; set; }
}

public class DebitCard : IAccount
{
    public required override string Type { get; set; } = AccountType.Bank;
}

On my repository I'm reading using the
IAccount
IAccount
interface and on my code whenever I need I eventually cast to
CreditCard
CreditCard
or
DebitCard
DebitCard
, but it is giving me this error:
 Error during MainService.Domain.Interfaces.IAccount GetAsync: Unable to determine actual type of object to deserialize for interface type MainService.Domain.Interfaces.IAccount.
 Error during MainService.Domain.Interfaces.IAccount GetAsync: Unable to determine actual type of object to deserialize for interface type MainService.Domain.Interfaces.IAccount.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

❔ MongoDB.Driver.MongoConnectionException:
C#CC# / help
3y ago
.NET MongoDB Driver - Unsupported Filter Contains
C#CC# / help
4y ago
❔ [MongoDB][C# driver] Where the fuck is FindOne ?
C#CC# / help
3y ago