Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Posted
Updated 28-Jun-20 11:37am

1 solution

Try:
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[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900