What does "Property where class => someFunction" mean in C #
I look through the EF7 code on Github and find a line that looks like this:
public virtual DbSet<TEntity> Set<TEntity>() where TEntity : class => _setInitializer.Value.CreateSet<TEntity>(this); I saw this syntax before at the class level, for example:
public class SomeClass<T> where T : class Which says that T must be a class type. But the line from the source EF7 confuses me. I'm not sure what he is doing.
This is a physique expression , new syntax in C # 6.
This is a method, not a property. C # does not allow you to create common properties.
This is the same as
public virtual DbSet<TEntity> Set<TEntity>() where TEntity : class { return _setInitializer.Value.CreateSet<TEntity>(this); } This syntax is really a bit confusing, but actually the lambda construct here has nothing to do with the general limitations. This is just the Expression-Bodied Method , which had a common limitation.
You can think of it as:
public virtual DbSet<TEntity> Set<TEntity>() where TEntity : class { return _setInitializer.Value.CreateSet<TEntity>(this); } See Roslyn Wiki
This is a C # 6.0 feature called the Expression Bodied Method.
Read about it here .
The code is equivalent to:
public virtual DbSet<TEntity> Set<TEntity>() where TEntity : class { return _setInitializer.Value.CreateSet<TEntity>(this); }