我有英镑服务
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),
....
};
}
}
现在的问题是当我从存储中获取数据时。 保存工作正常但是当我获取时我得到“从 String 到 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 时,我为所有索引指定了不同的名称,但我没有遇到任何此类问题。
(顺便说一句,将所有索引名称移动到某处的字符串常量中可能也是个好主意。这应该有助于避免输入错误,并且您还应该获得对它们的 IntelliSense 支持。)
关于c# - 银光 : Sterling Throws Exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6723689/