What is the difference between IDbSet and DbSet?

What's the difference between

public IDbSet<Chrip> Chirps { get; set; } 

and

public DbSet<Chrip> Chirps { get; set; }  

Are they the same?

+4
source share
2 answers

Sam, I answer , clearly defines the difference between an interface and a class, but there are additional considerations when choosing a use case in your code.

In particular, a class can implement more than one interface or it can implement methods and properties that are not defined by any interface.

IDbSet<TEntity> , DbSet<TEntity>, . , FindAsync, RemoveRange SqlQuery . , .

, MSDN IDbSet<TEntity> :

IDbSet<TEntity> (mocks ) DbSet<TEntity>. , , . , EF6, , DbSet<TEntity> .

, , , , DbSet<TEntity> IDbSet<TEntity>, .

+14

, I, . , .

DbSet IDbSet


,

public interface IFoo
{
    int Echo(int bar);
}

public class Foo : IFoo
{
    public int Echo(int bar)
    {
        return bar;
    }
}

, Foo , , Echo, int int.

, , , . . .

+1

Source: https://habr.com/ru/post/1648281/


All Articles