简体   繁体   English

System.DayOfWeek枚举-保存时由于KnownType问题导致的实体错误; DevForce 2012年

[英]System.DayOfWeek enum - Entity errors on save with KnownType issues; DevForce 2012

DevForce 2012 7.2.2, EF 5, Silverlight, C#, VS2012 DevForce 2012 7.2.2,EF 5,Silverlight,C#,VS2012

Entity property of type System.DayOfWeek , erroring (full error messages below) that it needs to be added to the list of known types when trying to update/save a change of this property to a different value. 类型为System.DayOfWeek实体属性,发生错误(以下是完整的错误消息),在尝试将此属性的更改更新/保存为其他值时需要将其添加到已知类型的列表中。 Seems odd, considering it's a System Enumerable, and it's listed as a specific example that can be used in the DevForce documentation ( http://drc.ideablade.com/devforce-2012/bin/view/Documentation/enum-types ) 考虑到它是系统可枚举的,这似乎很奇怪,并且将其列为可以在DevForce文档中使用的特定示例( http://drc.ideablade.com/devforce-2012/bin/view/Documentation/enum-types

So I created an IKnownTypeProvider and added DayOfWeek as an entry: 因此,我创建了一个IKnownTypeProvider并添加了DayOfWeek作为条目:

public class LwKnownTypeProvider : IKnownTypeProvider
{
    public IEnumerable<Type> AddKnownTypes()
    {
        var list = new Type[]
                       {
                           typeof (DayOfWeek)
                       };
        return list;
    }
}

For fun, I also tried being a bit more specific, in case there was somewhere the tools were getting confused (replace DayOfWeek with System.DayOfWeek throughout), but this yielded the same results. 为了好玩,我还尝试更加具体一些,以防工具出现混乱(将DayOfWeek替换为System.DayOfWeek ),但这产生了相同的结果。

Things I've checked: 我检查过的事情:

  • Is the IKnownTypeProvider being found? 是否找到IKnownTypeProvider Breakpoints successfully being hit 断点成功被击中
  • Is it on both the SL & Server side? 在SL和Server端都一样吗? Yes, the class definition file is in both projects. 是的,两个项目中都包含类定义文件。 Yes, it's listed in collection of known types (provided by var lstKnownTypes = IdeaBlade.EntityModel.KnownTypeHelper.GetServiceKnownTypes(null); ) 是的,它列在已知类型的集合中(由var lstKnownTypes = IdeaBlade.EntityModel.KnownTypeHelper.GetServiceKnownTypes(null);

Inherited code, so maybe I'm overlooking something, but I'm not seeing it. 继承的代码,所以也许我忽略了某些内容,但没有看到它。

Error saving changes prior to adding the IKnownTypeProvider: 在添加IKnownTypeProvider之前保存更改时出错:

Type 'System.DayOfWeek' with data contract name DayOfWeek: http://schemas.datacontract.org/2005/07/system ' is not expected. 键入“ System.DayOfWeek”,其数据合同名称为DayOfWeek: http : //schemas.datacontract.org/2005/07/system不应为预期值。 Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute or by adding them to the list of known types passed to DataContractSerializer 将任何静态未知的类型添加到已知类型的列表中-例如,通过使用KnownTypeAttribute或将它们添加到传递给DataContractSerializer的已知类型的列表中

Error after adding the IKnownTypeProvider listed above: 添加IKnownTypeProvider列出的IKnownTypeProvider后发生错误:

The formatter thew an exception while trying to deserialize the message: There was an error while trying to deserialize parameter ideablade.com/EntityModel:workState. 格式化程序尝试反序列化消息时发生异常:尝试反序列化参数ideablade.com/EntityModel:workState时发生错误。 The InnerException message was 'Element 'ideablade.com/EntityModel:OriginalValue' contains data from a type that maps to the name ' http://schemas.datacontract.org/2005/07/System:DayOfWeek '. InnerException消息是“元素'ideablade.com/EntityModel:OriginalValue'包含来自映射到名称' http://schemas.datacontract.org/2005/07/System:DayOfWeek '的类型的数据。 The deserializer has no knowledge of any type that maps to this name. 解串器不知道任何映射到该名称的类型。 Consider using a DataContractResolver or add the type corresponding to 'DayOfWeek' to the list of known types - for example, by adding the KnownTypeAttribute attribute or by adding it to the list of known types pased to DataContractSerializer.'. 考虑使用DataContractResolver或将与“ DayOfWeek”对应的类型添加到已知类型的列表中-例如,通过添加KnownTypeAttribute属性或将其添加到粘贴到DataContractSerializer的已知类型的列表中。 Please see InnerException for more details. 有关更多详细信息,请参见InnerException。

This appears to be a bug with how the enum types are handled during an update when these changed properties are part of the original values passed to the server. 当这些更改的属性是传递给服务器的原始值的一部分时,这似乎是在更新期间如何处理枚举类型的错误。 The workaround for now is to implement your IKnownTypeProvider on both client and server. 现在的解决方法是在客户端和服务器上实现IKnownTypeProvider。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM