0

I start in C# and I want to keep only some information in DB with a condition to a Child and is a Enum.

this is what i want to do but this not work.

var element = await _unitOfWork.Repository<TbElement>()
    .All( c => c
        .Include( x => x.el )
        .ThenInclude( x => x.ChildEl.Type == Type.bottle )
    );

My table El:

[ForeignKey("ChildElId")]
public         int?      ChildElId { get; set; }

public virtual TbChildEl ChildEl   { get; set; }

Table ChildEl:

public class TbChildEl : EntiteCSSAbstract
{
    public string            Name        { get; set; }
    public string            Description { get; set; }
    public bool              IsActif     { get; set; }
    public Type              Type        { get; set; }

    public ICollection<TbEl> El          { get; set; }
}


class TbEl
{
    public         int               UserId { get; set; }

    public virtual ICollection<TbEL> El     { get; set; }
}

I want to keep all bottle in this exemple, because is not the real name, but nothing work.

Can someone have a solution. It's meabe easy but I not found how to keep it without take all Id in Element and take Id to ChildEl with type=bootle and make a loop if element.El.ChildElId == ChildEl.Id if working but I know that not the good way and too long to run on Server.

Dai
  • 141,631
  • 28
  • 261
  • 374
Migne
  • 1
  • What ORM are you using? If you're using Entity Framework then it's likely you'll run into problems because using the `UnitOfWork` and Generic Repository anti-patterns are incompatible with EF (because your `DbContext` **already is** a unit-of-work, and its `DbSet` members **are already** implementations of the generic-repository: https://stackoverflow.com/questions/31516310/why-is-a-generic-repository-considered-an-anti-pattern – Dai Apr 13 '23 at 14:04
  • Are you saying you have `enum Type { bottle }` and it's used by `TbChildEl.Type`? If so, then you need to rename it: the name `Type` is already in-use in .NET. Also EF can use `enum` types just fine, but you need to set explicit const numeric values for each member. – Dai Apr 13 '23 at 14:09
  • Also, please use better names for your types than `class TbChildEl` and `TblEl` - why aren't you using full names (and avoiding Systems Hungarian prefixes like "Tb" and "El" - for "table" and "element", right?). – Dai Apr 13 '23 at 14:10
  • @Dai the name that I write here is not the real name of Table and element, just to make the structure. the Enum name est TypeNameEnum and the list in is: bottle, tire, etc. – Migne Apr 13 '23 at 17:47

0 Answers0