I used below syntax:
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
};
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With