Could Guid be DB key?

Apr 20, 2009 at 1:49 AM
Got error when save a object with guid as db key like:

Table table = new Table();
table.key=Guid.New();
Context.Save(table);

class Table:IDbObject
{
 public Guid key{get;set;}
}
Coordinator
Apr 20, 2009 at 3:31 AM
Lephone.UnitTest.Data.CommonUsageTest:


public abstract class GuidKey : DbObjectModel<GuidKey, Guid>
{
    public abstract string Name { get; set; }
}

[Test]
public void TestGuidKey()
{
    GuidKey o = GuidKey.New();
    Assert.IsTrue(Guid.Empty == o.Id);

    o.Name = "guid";
    o.Save();

    Assert.IsFalse(Guid.Empty == o.Id);

    GuidKey o1 = GuidKey.FindById(o.Id);
    Assert.AreEqual("guid", o1.Name);

    o.Name = "test";
    o.Save();

    GuidKey o2 = GuidKey.FindById(o.Id);
    Assert.AreEqual("test", o2.Name);

    o2.Delete();
    GuidKey o3 = GuidKey.FindById(o.Id);
    Assert.IsNull(o3);
}