ABP (ASP.NET Boilerplate) application development framework for teaching novice No.5 establish warehousing Repository

ABP (ASP.NET Boilerplate) application development framework for teaching novice No.5 establish warehousing Repository


ABP (ASP.NET Boilerplate) application development framework for teaching novice No.0 index


ABP has built-in storage features such as basic common CRUD, and we can expand

On the interface architecture is open and practical storage respectively in the Domain layer and infrastructure layer

Said first interface portion warehouse

Here to do a Map with an ID to get a storage interface corresponds Player collection

First, as we open with an architecture in Core project folder to put a IRepositories

MyCompany.MyProject.CoreIRepositories

Then we add a new interface IPlayerRepository.cs

using Abp.Domain.Repositories;
using MyCompany.MyProject.Entities;
using System.Collections.Generic;

namespace MyCompany.MyProject.IRepositories
{
    public interface IPlayerRepository : IRepository
  
  
   
   
    {
        List
   
   
    
     GetPlayersWithMap(long mapID);
    }
}
   
   
  
  

Then we completed the interface definition warehousing

The practical part we came AbsoluteDuo_V4.EntityFrameworkRepositories

PlayerRepository.cs establish a class that inherits the base class MyProjectRepositoryBase ABP offers and inheritance we have just defined interface IPlayerRepository

using Abp.EntityFramework;
using MyCompany.MyProject.Entities;
using MyCompany.MyProject.IRepositories;
using System.Collections.Generic;
using System.Linq;

namespace MyCompany.MyProject.EntityFramework.Repositories
{
    public class PlayerRepository : MyProjectRepositoryBase
  
  
   
   , IPlayerRepository
    {
        public PlayerRepository(IDbContextProvider
   
   
    
     dbContextProvider) : base(dbContextProvider)
        {

        }

        public List
    
    
     
      GetPlayersWithMap(long mapID)
        {
            // GetAll()返回一个IQueryable
     
     
      
      ,我们可以通过它来查询
            var query = GetAll();

            // 也可以直接使用EF的DbContext对象
            //var query2 = Context.Players.AsQueryable(); 

            // 另一种选择:直接使用Table属性代替"Context.Players",都是一样的。
            //var query3 = Table.AsQueryable();

            if (mapID > 0)
            {
                query = query.Where(c => c.MapID == mapID);
            }
            return query.ToList();
        }

        public async Task
      
      
        > GetPlayersWithMapAsync(long mapID) { return await GetAllListAsync(c => c.MapID == mapID); } } } 
      
     
     
    
    
   
   
  
  
  • GetAll ()
    returns IQueryable
    Because there is a delay characteristic Loading (Lazy Loading), the actual connection to the database is in use ToList () method
  • GetAllList ()
    returns List
    This is when the data will be removed immediately invoked from the data source

Side warehouse has been established to complete


Next

ABP (ASP.NET Boilerplate) application development framework for teaching novice No.6 build application services

reference

ABP framework to build step by step using formal project tutorial series

Original: Big Box  ABP (ASP.NET Boilerplate) application development framework for teaching novice No.5 establish warehousing Repository


Guess you like

Origin www.cnblogs.com/chinatrump/p/11505605.html