2011-10-19 57 views
3

我正在嘗試爲Oracle數據庫創建WCF數據服務。我正在使用Oracle實體框架適配器併爲所有視圖(其只讀服務)創建實體。我遇到的問題是DateTimeOffset不是受支持的基本類型。WCF數據服務和非原始類型

好吧,我已經使用了一個公平的位,這不是一個未知的問題,但我找不到答案!我無法編輯視圖來更改作爲其專有數據庫返回的類型。有些人提到使用RegisterKnownType(typeof(DateTimeOffset)),但這不起作用。其他人說我需要序列化數據,但沒有解釋如何。

有沒有人有一個一步一步的解決方案,以如何獲得WCF數據服務返回不受支持的基元類型?

回答

0

類似Best work around to fix DateTimeOffset over WCF Data Service issue

這有點使用反射,但投入應用下列啓動(我用WebActivator)迄今的工作我使用2011年10月CTP的黑客。

var primitiveResourceTypeMapType = typeof(ResourceType).Assembly.GetType("System.Data.Services.Providers.PrimitiveResourceTypeMap"); 
Debug.Assert(primitiveResourceTypeMapType != null); 
var builtInTypesMappingField = primitiveResourceTypeMapType.GetField("builtInTypesMapping", BindingFlags.NonPublic | BindingFlags.Static); 
Debug.Assert(builtInTypesMappingField != null); 

var existingMap = ((KeyValuePair<Type, string>[])builtInTypesMappingField.GetValue(null)).ToList(); 
existingMap.Add(new KeyValuePair<Type, string>(typeof(DateTimeOffset), "Edm.DateTimeOffset")); 
existingMap.Add(new KeyValuePair<Type, string>(typeof(DateTimeOffset?), "Edm.DateTimeOffset")); 
builtInTypesMappingField.SetValue(null, existingMap.ToArray());