Linq中的自定义列 [英] Customized column in Linq

查看:61
本文介绍了Linq中的自定义列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两种方法:

var books = _myIBookRepository.RetrieveAllBooks();  
var bokexamples = _myIbokexamples Repository.RetrieveAllBookExample();

两个数据库表:

BookExample

BookExample

  • BokExampleID(主键)
  • BookID(外键)
  • OrderDetailID(外键)

  • BookID(主键)
  • 类别ID(外键)
  • LanguageID(外键)
  • 标题

BookID是表BookExample中表BookExample中的外键

BookID is a foreign key in table BookExample from table Book

如果orderdetailID为NULL,则表示该specfik图书示例在商店中可用

If orderdetailID is NULL it means that this specfik bookexample is available in the store

目标:
显示两列,分别是标题"和可用库存". 库存量"是数据库中不存在的自定义列. 可用的库存"应包含数字,例如2本书的标题..可用.

Goal:
Display two column that is "Title" and "stock availiable". "stock availiable" is a customized column that don't exist in the database. "stock available" should contain numbers for instance 2 books of title .... is available.

问题:
无法在Linq中找到正确的源代码以显示这两栏.

Problem:
Having problem to find right source code in Linq in order to display these two column.

//Fullmetalboy

// Fullmetalboy

推荐答案

var query = from b in books
            select new
            {
                Title = b.Title,
                StockAvailable = bookexamples.Count(be => 
                        be.BookID == b.BookID && 
                        be.OrderDetailID == null
                    )
            };

如果我正确理解您的问题,那应该就是您要寻找的东西.

If I understand your question right, this should be what you're looking for.

这篇关于Linq中的自定义列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆