Castle AR 使用 Nullables 支持初态为 null 的数值属性
2006-09-25 16:19
148 查看
NullableModel.cs
namespace Castle.ActiveRecord.Tests.Model
{
using System;
using Nullables;
[ActiveRecord]
public class NullableModel : ActiveRecordBase
{
private int id;
private NullableInt32 age;
private NullableDateTime completion;
private NullableBoolean accepted;
public NullableModel()
{
}
[PrimaryKey]
public int Id
{
get { return id; }
set { id = value; }
}
[Property]
public NullableInt32 Age
{
get { return age; }
set { age = value; }
}
[Property]
public NullableDateTime Completion
{
get { return completion; }
set { completion = value; }
}
[Property]
public NullableBoolean Accepted
{
get { return accepted; }
set { accepted = value; }
}
public static void DeleteAll()
{
ActiveRecordBase.DeleteAll( typeof(NullableModel) );
}
public static NullableModel[] FindAll()
{
return (NullableModel[]) ActiveRecordBase.FindAll( typeof(NullableModel) );
}
public static NullableModel Find(int id)
{
return (NullableModel) ActiveRecordBase.FindByPrimaryKey( typeof(NullableModel), id );
}
}
}
NullableTestCase.cs
namespace Castle.ActiveRecord.Tests
{
using System;
using NUnit.Framework;
using Castle.ActiveRecord.Tests.Model;
[TestFixture]
public class NullablesTestCase : AbstractActiveRecordTest
{
[SetUp]
public void Init()
{
ActiveRecordStarter.Initialize( GetConfigSource(), typeof(NullableModel) );
Recreate();
}
[Test]
public void Usage()
{
NullableModel model = new NullableModel();
model.Save();
Assert.AreEqual(1, NullableModel.FindAll().Length);
model = NullableModel.FindAll()[0];
Assert.AreEqual(Nullables.NullableInt32.Default, model.Age);
Assert.AreEqual(Nullables.NullableDateTime.Default, model.Completion);
Assert.AreEqual(Nullables.NullableBoolean.Default, model.Accepted);
}
}
}
namespace Castle.ActiveRecord.Tests.Model
{
using System;
using Nullables;
[ActiveRecord]
public class NullableModel : ActiveRecordBase
{
private int id;
private NullableInt32 age;
private NullableDateTime completion;
private NullableBoolean accepted;
public NullableModel()
{
}
[PrimaryKey]
public int Id
{
get { return id; }
set { id = value; }
}
[Property]
public NullableInt32 Age
{
get { return age; }
set { age = value; }
}
[Property]
public NullableDateTime Completion
{
get { return completion; }
set { completion = value; }
}
[Property]
public NullableBoolean Accepted
{
get { return accepted; }
set { accepted = value; }
}
public static void DeleteAll()
{
ActiveRecordBase.DeleteAll( typeof(NullableModel) );
}
public static NullableModel[] FindAll()
{
return (NullableModel[]) ActiveRecordBase.FindAll( typeof(NullableModel) );
}
public static NullableModel Find(int id)
{
return (NullableModel) ActiveRecordBase.FindByPrimaryKey( typeof(NullableModel), id );
}
}
}
NullableTestCase.cs
namespace Castle.ActiveRecord.Tests
{
using System;
using NUnit.Framework;
using Castle.ActiveRecord.Tests.Model;
[TestFixture]
public class NullablesTestCase : AbstractActiveRecordTest
{
[SetUp]
public void Init()
{
ActiveRecordStarter.Initialize( GetConfigSource(), typeof(NullableModel) );
Recreate();
}
[Test]
public void Usage()
{
NullableModel model = new NullableModel();
model.Save();
Assert.AreEqual(1, NullableModel.FindAll().Length);
model = NullableModel.FindAll()[0];
Assert.AreEqual(Nullables.NullableInt32.Default, model.Age);
Assert.AreEqual(Nullables.NullableDateTime.Default, model.Completion);
Assert.AreEqual(Nullables.NullableBoolean.Default, model.Accepted);
}
}
}
相关文章推荐
- ocx使用时js报错"对象不支持的属性或方法"
- Javascript 找一组数字中的最大数的方法(附使用Math.max来检测浏览器支持哪个属性)
- Silverlight 之MVVM下 TextBox使用Binding可为空数值类型属性,修改文本框为空之后无效
- 使用jQuery解决IE不支持的option disable属性【转】
- springmvc mybatis 配置一对多的关系使用 <association> 及实体类写法2Spring MVC 会按请求参数名和 POJO 属性名进行自动匹配自动为该对象填充属性值。支持
- jQuery在IE8上使用,IE8提示“对象不支持此属性或方法”
- $.ajax 对象为null或者对象不支持此属性
- iOS上的safrai不支持使用关键字作为对象属性名称或方法名称
- 使用spring声明式事务,spring使用AOP来支持声明式事务,会根据事务属性,自动在方法调用之前决定是否开启一个事务,并在方法执行之后决定事务提交或回滚事务。
- ie8下面版本号(包含ie8)的浏览器不支持html5标签属性解决方式(Modernizr 2.6.2插件的使用)
- 使用PageMethods老是出现"PageMethods未定义"或"对象不支持此属性或方法"的解决方法
- table不支持 width属性,必须使用 style="width:1px;" 来设置宽度 width
- ie8以下版本(包括ie8)的浏览器不支持html5标签属性解决方案(Modernizr 2.6.2插件的使用)
- new 出的对象无法使用 @Autowired装配进来的属性,会报null
- sql2000备份的数据库还原到sql2005后,选择“数据库关系图”提示:此数据库没有有效所有者,因此无法安装数据库关系图支持对象。若要继续,请首先使用“数据库属性”对话框的“文件”页或 ALTER AUTHORIZATION 语句将数据库所
- 关于 CSS 浮动属性的行为、使用和支持的概览
- 使用qt内部数值动画实现弹簧效果的探索及属性带有{}和没有{}的区别
- sql2000备份的数据库还原到sql2005后,选择“数据库关系图”提示:此数据库没有有效所有者,因此无法安装数据库关系图支持对象。若要继续,请首先使用“数据库属性”对话框的“文件”页或 Alter AUTHORIZATION 语句将数据库
- mybatis支持属性使用驼峰的命名
- Visio文件使用类库Aspose.Diagram 新功能:支持形状的3D旋转属性