var query = (from a in context.Users from b in context.Companies from c in context.Accounts where a.Id == c.CreateUser && c.CompanyId == b.Id && c.AllPassState == false select new WaitAuditEntity { a,b,c }).ToList().select(x=>new{ //这里写一次 });
EF其实就是解析Expression。。生成SQL。。问题SQL不会如何把datetime转string。。所以你应该先Tolist。。把结果加载到内存当中,再用linq to object的select去转下
var query = from a in context.Users from b in context.Companies from c in context.Accounts let _CreateTime c.CreateTime.ToString(), _UpdateTime = c.UpdateTime.ToString() where a.Id == c.CreateUser && c.CompanyId == b.Id && c.AllPassState == false select new WaitAuditEntity { Id = c.Id, AccountName = c.AccountName, ContactName = c.ContactName, CompanyName = b.CompanyName, OpenCompany = a.BelongsCompany, Mobile = c.Mobile, AccountState = c.AccountState, PaymentState = c.PaymentState, ReviewState = c.ReviewState, EstablishState = c.EstablishState, AllPassState = c.AllPassState, CreateTime = _CreateTime , UpdateTime = _UpdateTime , CreateUserName = a.Name };
没有在sql语句转 在界面层转就可以了
EF其实就是解析Expression。。生成SQL。。问题SQL不会如何把datetime转string。。所以你应该先Tolist。。把结果加载到内存当中,再用linq to object的select去转下 嗯,稍稍改了一下: let _CreateTime c.CreateTime.ToString() let _UpdateTime = c.UpdateTime.ToString() 这样就可以了。谢谢各位
from b in context.Companies
from c in context.Accounts
where a.Id == c.CreateUser && c.CompanyId == b.Id && c.AllPassState == false
select new WaitAuditEntity
{
a,b,c
}).ToList().select(x=>new{
//这里写一次
});
EF其实就是解析Expression。。生成SQL。。问题SQL不会如何把datetime转string。。所以你应该先Tolist。。把结果加载到内存当中,再用linq to object的select去转下
from b in context.Companies
from c in context.Accounts
let _CreateTime c.CreateTime.ToString(), _UpdateTime = c.UpdateTime.ToString()
where a.Id == c.CreateUser && c.CompanyId == b.Id && c.AllPassState == false
select new WaitAuditEntity
{
Id = c.Id,
AccountName = c.AccountName,
ContactName = c.ContactName,
CompanyName = b.CompanyName,
OpenCompany = a.BelongsCompany,
Mobile = c.Mobile,
AccountState = c.AccountState,
PaymentState = c.PaymentState,
ReviewState = c.ReviewState,
EstablishState = c.EstablishState,
AllPassState = c.AllPassState,
CreateTime = _CreateTime ,
UpdateTime = _UpdateTime ,
CreateUserName = a.Name
};
在界面层转就可以了
EF其实就是解析Expression。。生成SQL。。问题SQL不会如何把datetime转string。。所以你应该先Tolist。。把结果加载到内存当中,再用linq to object的select去转下
嗯,稍稍改了一下: let _CreateTime c.CreateTime.ToString() let _UpdateTime = c.UpdateTime.ToString()
这样就可以了。谢谢各位