Silverlight: Sterling抛出异常
本文关键字:抛出异常 Sterling Silverlight | 更新日期: 2023-09-27 18:02:24
我有Sterling服务
public sealed class SterlingService : IApplicationService, IApplicationLifetimeAware, IDisposable
{
private SterlingEngine _engine;
private static readonly ISterlingDriver _driver = new IsolatedStorageDriver();
public static SterlingService Current { get; private set; }
public ISterlingDatabaseInstance Database { get; private set; }
public static void StartUpDatabase()
{
Current.Database = Current._engine.SterlingDatabase.RegisterDatabase<LocalDB>(_driver);
}
....
....
}
和我的LocalDB类,我有表的定义是:
public class LocalDB : BaseDatabaseInstance
{
protected override List<ITableDefinition> RegisterTables()
{
return new List<ITableDefinition>()
{
CreateTableDefinition<ContactData, Guid>(k => k.UID.Value)
.WithIndex<ContactData, int, Guid>("CustomerId", t => t.CustomerId.Value),
CreateTableDefinition<ContactDetailData, Guid>(k => k.ContactData.UID.Value)
.WithIndex<ContactDetailData, int, Guid>("CustomerId", t => t.ContactData.CustomerId.Value),
....
};
}
}
现在的问题是当我从存储中获取数据时。保存工作正常,但当我取我得到"无效的强制转换操作异常从字符串到Guid"。
public static List<ContactData> GetContactListFromLocalDB(int customerId)
{
var data = (from k in SterlingService.Current.Database.Query<ContactData, int, Guid>("CustomerId")
where k.LazyValue != null && k.Index == customerId
select k.LazyValue.Value);
return data.ToList<ContactData>(); (**HERE I GET THE EXCEPTION**)
}
请告诉我哪里做错了。
谢谢。
在多个索引中使用名称CustomerId
可能有问题。
尝试将索引的名称从CustomerId
更改为ContactData_CustomerId
和ContactDetailData_CustomerId
之类的东西(对于您没有向我们展示的任何其他索引也类似)。
我在Sterling文档中找不到任何东西表明名称必须是唯一的。尽管如此,当我使用Sterling时,我给我所有的索引起了不同的名字,我没有遇到任何这样的问题。
(顺便说一句,将所有索引名移到字符串常量中也是一个好主意。这应该有助于避免输入错误,并且您还应该为它们获得智能感知支持。
http://sterling.codeplex.com/workitem/14343