Click here to Skip to main content
14,577,223 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have an Interface:
public interface ICategory
int Id {Get; Set};
string name {Get; Set};
ICollection<iitems> Category {Get; Set};

public class Category:ICategory
public Category()
IItems = new HashSet<iitems>();

1. at the migration init it says that this is an interface and it will show in db and i have to igonre it

2. IItems = new HashSet<items>(); - Pre compile error

public int Id {Get; Set};
public string Name {Get; Set};
public ICollection<iitems> IItems {Get; Set};

I must to make all the project with interface, how can make it work?
if i'm doing ICategory<item> - it kills the all idea of interface.
how i can make this work in the sql so i will not have to ignore it:
public ICollection<IItems> IItems {Get; Set};

if i'm doing this:
public ICollection<Items> Items {Get; Set};

and then
Items = new HashSet<Items>();

It doesn't have errors but still kills the interface idea.

What I have tried:

I have tried all what i wrote above + dependency injection
Updated 28-Jun-20 11:37am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

public interface ICategory<T>
    public int Id {get; set};
    public string Name {get; set};
    public ICollection<T> Category {get; set};

See here: C# Programming: Creating and Using a Generic Interface[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100