211 Introduction to Repository

示例

添加一个.NET Core类库项目,项目名称RepositoryContracts

添加Entities项目引用

添加ICountriesRepository.cs

using Entities;

namespace RepositoryContracts
{
    /// <summary>
    /// Represents data access logic for managing Country entity
    /// </summary>
    public interface ICountriesRepository
    {
        /// <summary>
        /// Adds a new country object to the data store
        /// </summary>
        /// <param name="country">Country object to add</param>
        /// <returns>Returns the country object after adding it to the data store</returns>
        Task<Country?> AddCountryAsync(Country country);

        /// <summary>
        /// Returns all countries in the data store
        /// </summary>
        /// <returns>All countries from the table</returns>
        Task<IEnumerable<Country>?> GetAllCountriesAsync();

        /// <summary>
        /// Returns a country object based on the given country id;
        /// otherwise, it returns null
        /// </summary>
        /// <param name="countryId">CountryId to search</param>
        /// <returns>Matching country or null</returns>
        Task<Country?> GetCountryByCountryIdAsync(Guid countryId);


        /// <summary>
        /// Returns a country object based on the given country name
        /// </summary>
        /// <param name="countryName">Country name to search</param>
        /// <returns>Matching country or null</returns>
        Task<Country?> GetCountryByCountryNameAsync(string countryName);

    }
}

添加IPersonsRepository.cs

using Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace RepositoryContracts
{
    /// <summary>
    /// Represents data access logic for managing Person entity
    /// </summary>
    public interface IPersonsRepository
    {
        /// <summary>
        /// Adds a person object to the data store
        /// </summary>
        /// <param name="person">Person object to add</param>
        /// <returns>Returns the person object after adding it to the table</returns>
        Task<Person?> AddPersonAsync(Person person);

        /// <summary>
        /// Returns all persons in the data store
        /// </summary>
        /// <returns>List of person objects from table</returns>
        Task<IEnumerable<Person>?> GetAllPersonsAsync();

        /// <summary>
        /// Returns a person object based on the given person id
        /// </summary>
        /// <param name="personId">PersonId(guid) to search</param>
        /// <returns>A person object or null</returns>
        Task<Person?> GetPersonByPersonIdAsync(Guid personId);

        /// <summary>
        /// Returns all person objects based on the given expression
        /// </summary>
        /// <param name="predicate">LINQ expression to check</param>
        /// <returns>All matching persons with given condition</returns>
        Task<IEnumerable<Person>?> GetFilteredPersonsAsync(Expression<Func<Person,bool>> predicate);

        /// <summary>
        /// Deletes a person object based on the person id
        /// </summary>
        /// <param name="PersonId">Person Id(guid) to search</param>
        /// <returns>Returns true, if the deletion is successful, otherwise false</returns>
        Task<bool> DeletePersonByPersonId(Guid PersonId);

        /// <summary>
        /// Updates a person object(person name and other details) based on the given person id
        /// </summary>
        /// <param name="person">Person object to update</param>
        /// <returns>Returns the updated person object</returns>
        Task<Person?> UpdatePerson(Person person);
    }
}

Gitee获取源码:

https://gitee.com/huang_jianhua0101/asp.-net-core-8.git

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

黄健华Yeah

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值