I have a plugin with an ObjectContext which generates and works with Table1
The Table1 must join with the product table to show somethings in the admin.
I know that since my ObjectContext and NopCommerce ObjectContext are two different contexts they cannot join to each other.
So my question is how can I Map the existing Product tableto my ObjectContext to do the join operation ?
Or is it a better way to do the stuff ?
Currently I'm fetching datum and then I join tem this way which is not efficient :
var Result = (_DbRepoProductAnalyser.Table.AsEnumerable()
.Join(_DbRepoProducts.Table.Select(p=>new{Id=p.Id,PrdName=p.Name}).AsEnumerable()
,pa=>pa.IdProduct,pr=>pr.Id,(pa,pr)=>new {pa,pr})
.Select(x=>new AnalyseModel
{
Id=x.pa.Id,
Analysecount=x.pa.Analysecount,
AnalyseMax=x.pa.AnalyseMax,
ProductName=x.prd.PrdName
})).ToList();
the full code :
using System;
using System.Linq;
using Nop.Core;
using Nop.Core.Caching;
using Nop.Core.Data;
using Nop.Core.Domain.Catalog;
using Nop.Services.Configuration;
using NopTop.Plugin.Widgets.AnalyseProduct.Domain;
using NopTop.Plugin.Widgets.AnalyseProduct.Models;
namespace NopTop.Plugin.Widgets.AnalyseProduct.Services
{
public partial class AnalyseProductAdminService : IAnalyseProductAdminService
{
private IRepository<Product> _DbRepoProducts;
private readonly IRepository<NopTop_tbl_ProductAnalyser> _DbRepoProductAnalyser;
public AnalyseProductAdminService(
IRepository<Product> _DbRepoProducts,
IRepository<NopTop_tbl_ProductAnalyser> _DbRepoProductAnalyser
)
{
this._DbRepoProducts = _DbRepoProducts;
this._DbRepoProductAnalyser = _DbRepoProductAnalyser;
}
public IPagedList<AnalyseModel> GetAnalyseProductDomain(int pageIndex = 0, int pageSize = int.MaxValue)
{
var Result = (_DbRepoProductAnalyser.Table.AsEnumerable()
.Join(_DbRepoProducts.Table.Select(p=>new{Id=p.Id,PrdName=p.Name}).AsEnumerable()
,pa=>pa.IdProduct,pr=>pr.Id,(pa,pr)=>new {pa,pr})
.Select(x=>new AnalyseModel
{
Id=x.pa.Id,
Analysecount=x.pa.Analysecount,
AnalyseMax=x.pa.AnalyseMax,
ProductName=x.prd.PrdName
})).ToList();
}
}
}
I do not want to use tricky ways. I want to know what is the best way suggested by nopCommerce to join tables of plugins with nopcommerce tables.
Thanks.