我的情况的独特之处在于ID不能随机分配,因此我在实例中设置了它的值。我使用建模器创建了一个实体的几个实例。以下是创建的XML:
<cf:entity name="Test4" namespace="Amikids.TimeTracking" categoryPath="/Amikids.TimeTracking">
<cf:property name="Id" key="true" typeName="int" />
<cf:property name="Name" />
<cf:instance>
<cf:instanceValue name="Id">10</cf:instanceValue>
<cf:instanceValue name="Name">Test 1</cf:instanceValue>
</cf:instance>
<cf:instance>
<cf:instanceValue name="Id">20</cf:instanceValue>
<cf:instanceValue name="Name">Test 2</cf:instanceValue>
</cf:instance>
<cf:instance>
<cf:instanceValue name="Id">30</cf:instanceValue>
<cf:instanceValue name="Name">Test 3</cf:instanceValue>
</cf:instance>
</cf:entity>
有两件事情没有按预期发挥作用:
(以下内容仅显示在代码段中,以防止StackOverflow重新格式化我的列表,以便所有记录显示在一行上)
ID Name
1 Test 1
2 Test 2
3 Test 3
(以下内容仅显示在代码段中,以防止StackOverflow重新格式化我的列表,以便所有记录显示在一行上)
ID Name
1 Test 1
2 Test 2
3 Test 3
4 Test 1
5 Test 2
6 Test 3
答案 0 :(得分:0)
尽管在实例中指定ID似乎不起作用,但作为一个简单的解决方法,我使用代码创建了记录,这允许我指定ID。已使用以下代码段验证了这一点。
Amikids.TimeTracking.Test4 test4 = new Amikids.TimeTracking.Test4();
test4.Id = 100;
test4.Name = "Test 100";
test4.Save();
test4 = new Amikids.TimeTracking.Test4();
test4.Id = 200;
test4.Name = "Test 200";
test4.Save();