我一直在与BreezeJS了一段时间,我曾与它篦经验。 正如我开始开发在.NET移动应用程序,我决定给BreezeSharp一试。
我通过文件和待办事项样品去了,并成功创建项目在解释http://www.breezejs.com/breeze-sharp-documentation/get-your-feet-wet 。
我有矿上现有的网络API控制器(与BreezeJS的伟大工程)执行查询的一个问题。
下面是查询方法:
private async Task<IEnumerable<PriceBook>> QueryPriceBooksFrom(EntityManager entityManager)
{
try
{
var query = new EntityQuery<PriceBook>().From("PriceBooks");
var result = await entityManager.ExecuteQuery(query);
return result;
}
catch (Exception e)
{
MessageBox.Show(e.GetType().Name + ": " + e.Message);
return new PriceBook[0];
}
}
这里是从BeginInit在()的代码:
DataContext = this;
Configuration.Instance.ProbeAssemblies(typeof(PriceBook).Assembly);
var entityManager = new EntityManager("http://127.0.0.1:81/api/cache/");
entityManager.MetadataStore.NamingConvention = new NamingConvention().WithClientServerNamespaceMapping("clientNamespace", "serverNamespace");
entityManager.MetadataStore.AllowedMetadataMismatchTypes = MetadataMismatchType.AllAllowable;
entityManager.MetadataStore.MetadataMismatch += (s, e) =>
{
// Log the mismatch
var message = string.Format("{0} : Type = {1}, Property = {2}, Allow = {3}",
e.MetadataMismatchType, e.StructuralTypeName, e.PropertyName, e.Allow);
Console.WriteLine(message);
// Disallow missing navigation properties on the TodoItem entity type
if (e.MetadataMismatchType == MetadataMismatchType.MissingCLRNavigationProperty &&
e.StructuralTypeName.StartsWith("PriceBook"))
{
e.Allow = false;
}
};
这里是控制器的方法:
[HttpGet]
public IQueryable<PriceBook> PriceBooks(ODataQueryOptions options)
{
return ...;
}
我从BaseEntity继承客户价目表类有子集服务器价目表实体。
在控制器元数据的方法被击中,但我无法打PriceBooks方法。 相反,我得到的NullReferenceException:未将对象引用设置到对象的实例。
我曾尝试没有ODataQueryOptions参数,并与EntityQuery的各种版本,但没有成功。
当我尝试调用entityManager.fetchMetadata(例外的情况不会发生),但获取价目表时元数据的方法被再次调用。
有没有人有想法可能是什么问题?
编辑 :这是问题的堆栈跟踪:
at Breeze.Sharp.CsdlMetadataProcessor.ParseCsdlDataProperty(StructuralType parentType, JObject csdlProperty, List`1 keyNamesOnServer) in c:\GitHub\breeze.sharp\Breeze.Sharp\CsdlMetadataProcessor.cs:line 136
at Breeze.Sharp.CsdlMetadataProcessor.<>c__DisplayClass14.<ParseCsdlEntityType>b__10(JToken csdlDataProp) in c:\GitHub\breeze.sharp\Breeze.Sharp\CsdlMetadataProcessor.cs:line 109
at Breeze.Sharp.Core.EnumerableFns.ForEach[T](IEnumerable`1 items, Action`1 action) in c:\GitHub\breeze.sharp\Breeze.Sharp\Core\EnumerableFns.cs:line 35
at Breeze.Sharp.CsdlMetadataProcessor.ParseCsdlEntityType(JObject csdlEntityType) in c:\GitHub\breeze.sharp\Breeze.Sharp\CsdlMetadataProcessor.cs:line 108
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Breeze.Sharp.CsdlMetadataProcessor.ProcessMetadata(MetadataStore metadataStore, String jsonMetadata) in c:\GitHub\breeze.sharp\Breeze.Sharp\CsdlMetadataProcessor.cs:line 33
at Breeze.Sharp.MetadataStore.<FetchMetadata>d__a.MoveNext() in c:\GitHub\breeze.sharp\Breeze.Sharp\MetadataStore.cs:line 166
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Breeze.Sharp.EntityManager.<FetchMetadata>d__3.MoveNext() in c:\GitHub\breeze.sharp\Breeze.Sharp\EntityManager.cs:line 198
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Breeze.Sharp.EntityManager.<ExecuteQuery>d__b.MoveNext() in c:\GitHub\breeze.sharp\Breeze.Sharp\EntityManager.cs:line 230
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Breeze.Sharp.EntityManager.<ExecuteQuery>d__6`1.MoveNext() in c:\GitHub\breeze.sharp\Breeze.Sharp\EntityManager.cs:line 208
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at StanleySteemer.Nimbus.Mobile.MainWindow.<QueryPriceBooksFrom>d__9.MoveNext() in c:\Projects\SSI\Nimbus\source\StanleySteemer.Nimbus.Mobile\MainWindow.xaml.cs:line 109
解决方案 :我想通了,问题是用枚举属性。 我已经要求对我的客户省去服务器枚举属性:
[必填]公众的DataStore数据存储{获得; 组; }
我加入这个属性到客户端固定的空引用的问题。 现在我有问题与解析该枚举,但这是另外一个问题。