English 中文(简体)
在 linq 中使用内部连接
原标题:Use inner join in linq
  • 时间:2012-05-24 05:39:19
  •  标签:
  • c#
  • linq

请帮助我加入Venee Conserent(MVC 4)的表格,

源代码 :

public ViewResult List(int page = 1)
{
    EmployeListViewModel viewModel = new EmployeListViewModel
    {
        Employes = repository.Сотрудник
        .OrderBy(e => e.FAM).ThenBy(n => n.Name).Skip((page - 1) * PageSize)
        .Take(PageSize),
        PagingInfo = new PagingInfo
        {
            CurrentPage = page,
            itemsPerPage = PageSize,
            TotalItems = repository.Сотрудник.Count()
        }
    };
    return View(viewModel);
}

雇员资料库:

using System.Linq;
using WebService.Domain.Abstract;
using WebService.Domain.Entities;

namespace WebService.Concrete
{
    public class EFEmployeRepository: IEmployeRepository
    {
        private EFDbContext context = new EFDbContext();

       public IQueryable<Сотрудник> Сотрудник
        {
            get { return context.Сотрудник; }
        }
    }
}

我需要帮助才能加入 & [appointmnet_id] 的表格 [ID] 。

问题回答

在\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

<强度 > EDIT: 代码样本

类定义 :

public class Сотрудник {
    ...

    public int appointmnet_id { get; set; }
    [ForeignKey(appointment_id)]
    public Должность appointment { get; set; }
}

仓库方法 :

public List<Сотрудник> GetStuff(int page, int PageSize) {
    return (
        from e in repository.Сотрудник.Include("appointment")
        orderby e.FAM
        thenby e.Name
        select e
    ).Skip((page - 1) * PageSize).Take(PageSize).ToList();
}

MVC 行动:

public ViewResult List(int page = 1)
{
    EmployeListViewModel viewModel = new EmployeListViewModel
    {
        Employes = GetStuff(page, PageSize),
        PagingInfo = new PagingInfo
        {
            CurrentPage = page,
            itemsPerPage = PageSize,
            TotalItems = repository.Сотрудник.Count()
        }
    };
    return View(viewModel);
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签