"空值不能分配给类型System.Int32一个成员是一个非空的值类型" [英] "The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type."
问题描述
我有一个WCF服务(服务)。这些服务管理数据。但现在我有一个LINQ查询选择数据的问题。我得到一个消息的空值不能分配给类型System.Int32一个成员是一个非空的值类型。
I have a WCF service (services). The services manage the data. But now I have problems by selecting data in a LINQ-query. I get a message "The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type."
通过调试,我第一次通过方法走,你会完成对异常行。当我把后面的调试线(黄标)放入行// 08,然后我通过一切顺利的方法走。
By debugging the first time I walk through the method you'll finish to the exception-line. When I put back the debugger line (the yellow marked one) onto line "// 08", and then I walk through the method everything goes fine.
private static ResultClass Geselecteerd(int AID_Artiest) // 01
{ // 02
ResultClass _Result = new ResultClass(); // 03
string sMethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;// 04
// 05
try // 06
{ // 07
var recArtiest = (from artiest in DatabaseControl.GetDatabeheer.DataContext.ARTIESTs // 08
where artiest.ID_ARTIEST == AID_Artiest
select artiest).SingleOrDefault();
if (recArtiest != null)
{
ArtiestDataType.ID_Artiest = recArtiest.ID_ARTIEST;
ArtiestDataType.Artiestnaam = recArtiest.ARTIESTNAAM;
ArtiestDataType.Voorvoegsel = recArtiest.VOORVOEGSEL;
ArtiestDataType.Product = recArtiest.PRODUCT;
ArtiestDataType.ID_Categorie = recArtiest.ID_CATEGORIE;
ArtiestDataType.ID_Genre = recArtiest.ID_GENRE;
ArtiestDataType.Is_Band = BasisDataType.GetBoolString(recArtiest.IS_BAND);
ArtiestDataType.Land = recArtiest.LAND;
ArtiestDataType.Plaats = recArtiest.PLAATS;
ArtiestDataType.Website = recArtiest.WEBSITE;
ArtiestDataType.DatumInvoer = recArtiest.DATUM_INVOER;
ArtiestDataType.DatumMutatie = recArtiest.DATUM_MUTATIE;
}
}
catch (Exception ex)
{
string sFoutmelding = "Kan geen selectie maken.";
FLogboek.AddFoutmelding(FClassName, sMethodName, sFoutmelding, ex.Message);
_Result.Code = ResultCode.FATAAL;
_Result.Melding = sFoutmelding;
}
return _Result;
}
ID_ARTIEST是一个整数字段,它是主键了。需要字段的值和NULL值是不可能的。
这个方法一直工作。当我添加新的服务问题开始
我的问题是:什么我错了?具有与服务呢? 我必须拖延这一进程?
能有人给我一些建议吗?我已经8服务引用。如果你缺少一些必要的资源,我可以添加它。
My question is: What do I wrong? Has is to do with the service? Do I have to delay the process? Can anybody give me some tips? I've 8 service references. If you're missing some essential sources, I can add it.
我现在只有一个变通。
我已经加入的try-catch在try-catch区域内。然后,我没有得到任何的异常。它具有与性能有关。 我需要一个异步的解决方案?
I have now only a work-around. I have added try-catch inside the try-catch area. And then I didn't get any exception. It has to do with the performance. Do I need an Async-solution?
感谢。
推荐答案
几乎可以肯定发生了什么是类型 ARTIESTs
在 DatabaseControl.GetDatabeheer.DataContext.ARTIESTs 属性之一code>的类型
INT?
(这意味着空整型)的。
Almost certainly what is happening is one of the properties of the type ARTIESTs
in DatabaseControl.GetDatabeheer.DataContext.ARTIESTs
is of type int?
(which means nullable integer).
在猜测我会说这是不是 ID_CATEGORIE
或 ID_GENRE
。
At a guess I would say it's either ID_CATEGORIE
or ID_GENRE
.
您将需要修改你的类型的等值财产 ArtiestDataType
也属于类型<$的C $ C> INT?。
You will need to modify the equivalent property of your type ArtiestDataType
to also be of type int?
.
这将解决您的问题。
这篇关于"空值不能分配给类型System.Int32一个成员是一个非空的值类型"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!