Interface IGenericRepository<TEntity>
Interface representing a repository.
Inherited Members
Namespace:Intranet.Common
Assembly:Intranet.Common.dll
Syntax
public interface IGenericRepository<TEntity> : IDisposable where TEntity : class
Type Parameters
Name | Description |
---|---|
TEntity | The type of the entities in the repository. |
Methods
| Improve this Doc View SourceAdd(TEntity)
Adds the given entity to the repository.
Declaration
TEntity Add(TEntity entity)
Parameters
Type | Name | Description |
---|---|---|
TEntity | entity | The entity to add. |
Returns
Type | Description |
---|---|
TEntity | Returns the added entity. |
AddRange(IEnumerable<TEntity>)
Adds the given collection of entities into context underlying the set with each entity being put into the Added state such that it will be inserted into the database when SaveChangesAsync is called.
Declaration
IEnumerable<TEntity> AddRange(IEnumerable<TEntity> entities)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<TEntity> | entities | The collection of entities to add. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<TEntity> | The collection of entities. |
Attach(TEntity)
Attaches the given entity to the current database context.
Declaration
TEntity Attach(TEntity entity)
Parameters
Type | Name | Description |
---|---|---|
TEntity | entity | The entity to attach. |
Returns
Type | Description |
---|---|
TEntity | Returns the attached entity. |
CountRecords()
Gets the number of records of the repositories table.
Declaration
int CountRecords()
Returns
Type | Description |
---|---|
System.Int32 | Returns the number records of the repositories table. |
CountRecordsAsync()
Gets the number of records of the repositories table asynchronously.
Declaration
Task<int> CountRecordsAsync()
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Int32> | Returns the number records of the repositories table. |
Entry<TAnyEntity>(TAnyEntity)
Gets a System.Data.Entity.Infrastructure.DbEntityEntry<TEntity> Object for the given entity providing access to information about the entity and the ability to perform actions on the entity.
Declaration
DbEntityEntry<TAnyEntity> Entry<TAnyEntity>(TAnyEntity entity)where TAnyEntity : class
Parameters
Type | Name | Description |
---|---|---|
TAnyEntity | entity | The entity. |
Returns
Type | Description |
---|---|
System.Data.Entity.Infrastructure.DbEntityEntry<TAnyEntity> | Returns an entry for the entity. |
Type Parameters
Name | Description |
---|---|
TAnyEntity | The type of the entity. |
FindAsync(Object[])
Asynchronously finds an entity with the given primary key values. If an entity with the given primary key values exists in the context, then it is returned immediately without making a request to the store. Otherwise, a request is made to the store for an entity with the given primary key values and this entity, if found, is attached to the context and returned. If no entity is found in the context or the store, then null is returned.
Declaration
Task<TEntity> FindAsync(params object[] keyValues)
Parameters
Type | Name | Description |
---|---|---|
System.Object[] | keyValues | The values of the primary key for the entity to be found. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<TEntity> | A task that represents the asynchronous find operation. The task result contains the entity found, or null. |
Remarks
The ordering of composite key values is as defined in the EDM, which is in turn as defined in the designer, by the Code First fluent API, or by the DataMember attribute. Multiple active operations on the same context instance are not supported. Use 'await' to ensure that any asynchronous operations have completed before calling another method on this context.
GetAll()
Gets all entities.
Declaration
IQueryable<TEntity> GetAll()
Returns
Type | Description |
---|---|
System.Linq.IQueryable<TEntity> | All entities |
Remove(TEntity)
Removes the given entity from the repository.
Declaration
TEntity Remove(TEntity entity)
Parameters
Type | Name | Description |
---|---|---|
TEntity | entity | The entity to remove. |
Returns
Type | Description |
---|---|
TEntity | Returns the removed entity. |
SaveChanges()
Saves all changes made in this context to the underlying database.
Declaration
int SaveChanges()
Returns
Type | Description |
---|---|
System.Int32 | Returns the number of Objects written to the underlying database. |
SaveChangesAsync(Nullable<CancellationToken>)
Asynchronously saves all changes made in this context to the underlying database.
Declaration
Task<int> SaveChangesAsync(CancellationToken? cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.Threading.CancellationToken> | cancellationToken | A System.Threading.CancellationToken to observe while waiting for the task to complete. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Int32> | A task that represents the asynchronous save operation. The task result contains the number of Objects written to the underlying database. |
SetModified(TEntity)
Sets the state of the given entity to modified.
Declaration
void SetModified(TEntity entity)
Parameters
Type | Name | Description |
---|---|---|
TEntity | entity | The entity to mark as modified. |
SqlQuery(String, Object[])
Creates a raw SQL query that will return entities in this set. By default, the entities returned are tracked by the context; this can be changed by calling AsNoTracking on the System.Data.Entity.Infrastructure.DbSqlQuery<TEntity> returned. Note that the entities returned are always of the type for this set and never of a derived type. If the table or tables queried may contain data for other entity types, then the SQL query must be written appropriately to ensure that only entities of the correct type are returned. As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query String and then supply parameter values as additional arguments. Any parameter values you supply will automatically be converted to a DbParameter. context.Blogs.SqlQuery("SELECT * FROM dbo.Posts WHERE Author = @p0", userSuppliedAuthor); Alternatively, you can also construct a DbParameter and supply it to SqlQuery. This allows you to use named parameters in the SQL query string . context.Blogs.SqlQuery("SELECT * FROM dbo.Posts WHERE Author = @author", new SqlParameter("@author", userSuppliedAuthor));
Declaration
DbSqlQuery<TEntity> SqlQuery(string sql, params object[] parameters)
Parameters
Type | Name | Description |
---|---|---|
System.String | sql | The SQL query string . |
System.Object[] | parameters | The parameters to apply to the SQL query string . If output parameters are used, their values will not be available until the results have been read completely. This is due to the underlying behavior of DbDataReader, see http://go.microsoft.com/fwlink/?LinkID=398589 for more details. |
Returns
Type | Description |
---|---|
System.Data.Entity.Infrastructure.DbSqlQuery<TEntity> | A System.Data.Entity.Infrastructure.DbSqlQuery<TEntity> Object that will execute the query when it is enumerated. |
Where(Expression<Func<TEntity, Boolean>>)
Gets the entities matching the given predicate.
Declaration
IQueryable<TEntity> Where(Expression<Func<TEntity, bool>> predicate)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression<System.Func<TEntity, System.Boolean>> | predicate | The predicate. |
Returns
Type | Description |
---|---|
System.Linq.IQueryable<TEntity> | The entities matching the given predicate. |