Replies: 4 comments 2 replies
-
什么数据库,我用mysql,第一种写反而是错误的。 |
Beta Was this translation helpful? Give feedback.
-
Convert.ToBoolean 解析时会翻译成 cast ( xx as |
Beta Was this translation helpful? Give feedback.
-
sql server local db test var testDto11 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto
{
id = a.Id,
name = a.Title,
State = a.State == null ? false : (Boolean)a.State
}); 这是正常的 SELECT TOP 10 a__Type.[ParentId] as1, a.[Id] as2, a.[Title] as3, (case when a.[State] IS NULL then 0 else a.[State] end) as4
FROM [tb_topic22] a
LEFT JOIN [TestTypeInfo] a__Type ON a__Type.[Guid] = a.[TypeGuid]
换成Convert.ToBoolean(a.State) var testDto12 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto
{
id = a.Id,
name = a.Title,
State = a.State == null ? false : Convert.ToBoolean(a.State)
}); 生成的sql多了not in 报错 Incorrect syntax near the keyword 'not'. SELECT TOP 10 a__Type.[ParentId] as1, a.[Id] as2, a.[Title] as3, (case when a.[State] IS NULL then 0 else (cast(a.[State] as varchar) not in ('0','false')) end) as4
FROM [tb_topic22] a
LEFT JOIN [TestTypeInfo] a__Type ON a__Type.[Guid] = a.[TypeGuid] 在sql server 中,应该是else 不支持 表达式? |
Beta Was this translation helpful? Give feedback.
-
在sqlserver下 |
Beta Was this translation helpful? Give feedback.
-
State = a.State == null ? false : (bool)a.State 这么写是正确的
State = a.State == null ? false : Convert.ToBoolean(a.State), 这样写生成语句报错
Beta Was this translation helpful? Give feedback.
All reactions