Subsonic 3 Active Record TestRepository 标识列未增加 [英] Subsonic 3 Active Record TestRepository identity column not incremented

查看:23
本文介绍了Subsonic 3 Active Record TestRepository 标识列未增加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Subsonic 3.0.0.3 进行单元测试.单元测试按预期运行,记录计数断言通过.但是,测试框架不会自动增加标识列.

I am Unit Testing with Subsonic 3.0.0.3. Unit tests ran as expected with record count assertions passing. However the testing framework does not auto increment identity columns.

例如

var p1 = new Person() { Name = "Jack" };
p1.Add();
var p2 = new Person() { Name = "Jill" };
p2..Add();
var t1 = Person.SingleOrDefault(p => p.Name == "Jack");
var t2 = Person.SingleOrDefault(p => p.Name == "Jill");

T4模板读取的表结构

CREATE TABLE Person
(
    Id int IDENTITY(1,1) PRIMARY KEY
    ,Name NVARCHAR(255) NOT NULL 
)

连接字符串

<add name="SomeDb" connectionString="Test"/>

t1 和 t2 按预期设置了 name 属性,但两者的 Id 属性均为 0.

t1 and t2 have the name property set as expected, but the Id property is 0 for both.

这是故意的吗?如果是这样,如何处理需要通过ID选择记录的测试?

Is this by design? If so how to deal with tests that require selecting records by ID?

推荐答案

TestRepository 不知道你的 DB 位是如何设置的(怎么可能?)所以如果你想让它自动递增,你需要设置它自己.

The TestRepository has no idea how your DB bits are set (how could it?) so if you want it to auto-increment you'll need to set it yourself.

这篇关于Subsonic 3 Active Record TestRepository 标识列未增加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆