lovebetmvc使用linq to sql进行sum统计遇到查询也null的题材。AndroidStudio 使用gradle依赖过程出现的题目。

mvc linq to sql,linq to entity,sum,null

现象

Error:(75, 1) A problem occurred evaluating project ‘:common’.

Cannot convert a null value to an object of type Dependency.

The following types/formats are supported:

Instances of Dependency.

String or CharSequence values, for example ‘org.gradle:gradle-core:1.0’.

Maps, for example [group: ‘org.gradle’, name: ‘gradle-core’, version:
‘1.0’].

FileCollections, for example files(‘some.jar’, ‘someOther.jar’).

Projects, for example project(‘:some:project:path’).

ClassPathNotation, for example gradleApi().

Comprehensive documentation on dependency notations is available in DSL
reference for DependencyHandler type.

昨写了段sum的统计语句,

原因

究竟的gradle删掉了 依赖 但是模块里面还在靠 导致编译报错

decimal sums

sums = (
from fac in db.Apply
where  fa.state == 1
select fac.num
).Sum(),

下一场同运行,报错

Message=The cast to value type ‘System.Decimal’ failed because the
materialized value is null. Either the result type’s generic parameter
or the query must use a nullable type.

盖查询也空。在网上纠结了好悠久,找到一个办法,小改一下

select new{ s=fac.num}).Sum(x=>x.s as decimal?),

如此一改后,在LinqPad5高达测试通过,但是其实于先后及会报

Message=The ‘TypeAs’ expression with an input of type ‘System.Decimal’
and a check of type ‘System.Nullable`1[[System.Decimal, mscorlib,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]’
is not supported. Only entity types and complex types are supported in
LINQ to Entities queries.

头要命,这同的Linq to sql,怎么就很了也?

继续查,

可行措施是

select fac.num
).DefaultIfEmpty(0).Sum(),这样就OK了。

另外,SqlFunction在linq to
entity中因故无了,我而了继还见面报错,暂时不明原因,目前呢从未时间去解决此问题。

相关文章