本文介绍了如何选择LINQ各个领域加上一些新的领域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
- 我有一个RDLC报告
- 日期存储在SQL数据库格式是格鲁吉亚。我要显示在报告日为波斯语。
- 使用LINQ我想除了选择DB各个领域的一些新的领域被用作波斯日期字段。
我用下面的语法:
var invoices = from invoice in dbContext.eve_Invoices
select new
{
invoice.CreatorID,
invoice.DateChange,
invoice.DateCreation,
invoice.DatePrint,
invoice.Discount,
invoice.DiscountPercentage,
invoice.DiscountType,
invoice.Fare,
invoice.ID,
invoice.InvoiceStatus,
invoice.NumberOfItems,
invoice.Packaging,
invoice.PrintID,
invoice.RawPrice,
invoice.RoundOff,
invoice.ServiceCharge,
invoice.ServingType,
invoice.TableID,
invoice.Tax,
invoice.TotalPrice,
invoice.ValidityStatus,
PersianYear = invoice.DateCreation != null ? pc.GetYear((DateTime)invoice.DateCreation) : 0,
PersianMonth = invoice.DateCreation != null ? pc.GetDayOfMonth((DateTime)invoice.DateCreation) : 0,
PersianDay = invoice.DateCreation != null ? pc.GetDayOfMonth((DateTime)invoice.DateCreation) : 0
};
有没有办法通过发票的各个领域,除了新的领域,如:
is there any way to pass all fields of invoice in addition to new fields such as:
var invoices = from invoice in dbContext.eve_Invoices
select new
{
invoice.*,
PersianYear = invoice.DateCreation != null ? pc.GetYear((DateTime)invoice.DateCreation) : 0,
PersianMonth = invoice.DateCreation != null ? pc.GetDayOfMonth((DateTime)invoice.DateCreation) : 0,
PersianDay = invoice.DateCreation != null ? pc.GetDayOfMonth((DateTime)invoice.DateCreation) : 0
};
我也尝试选择新的{发票,...}但它不会导致到同一数据表作为第一个。
I also tried select new {invoice,....} however it will not result to datatable same as first one.
推荐答案
您可以通过所有的精密组件,但它不漂亮,这是更好地传递发票本身,而不是其字段:
You can pass all the feilds, but it's not beautiful, it's better to pass invoice itself, instead of its fields:
var invoices = from invoice in dbContext.eve_Invoices
select new
{
RelatedInvoice = invoice,
PersianYear = invoice.DateCreation != null ? pc.GetYear((DateTime)invoice.DateCreation) : 0,
PersianMonth = invoice.DateCreation != null ? pc.GetDayOfMonth((DateTime)invoice.DateCreation) : 0,
PersianDay = invoice.DateCreation != null ? pc.GetDayOfMonth((DateTime)invoice.DateCreation) : 0
};
PS:我不知道这行linq2entities(用心做事很有些日子我不吨有任何IDE和我忘了一切:):
P.S: I'm not sure this lines work carefully in linq2entities(it is some days i don't have any IDE and I forgot everything:):
PersianDay = invoice.DateCreation != null ? pc.GetDayOfMonth((DateTime)invoice.DateCreation) : 0
如果这不起作用,我建议第一个读取数据,然后做转换。
If this doesn't work I suggest first fetch data and then do conversion.
这篇关于如何选择LINQ各个领域加上一些新的领域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!