using System;
using Gentle.Common;
using Gentle.Framework;
using Gentle.Provider.SQLServer;
using log4net;
using QuickGraph;
namespace GentleExample1
{
[TableName("Users")]
public class User : Persistent
{
private int userId;
private string userName; // this is used by clients to construct new users
public User( string userName ) : this( 0, userName ) {} // this is used by Gentle to reconstruct objects read from the database
public User( int userId, string userName )
{
this.userId = userId;
this.userName = userName;
} // this is used by client to fetch users from the database
static public User Retrieve( int userId )
{
Key key = new Key( typeof(User), true, "Id", userId );
return Broker.RetrieveInstance( typeof(User), key ) as User;
} [TableColumn("UserId"), PrimaryKey(AutoGenerated=true)]
public int Id
{
get{ return userId; }
set{ userId = value; }
} [TableColumn(NotNull=true)]
public string Name
{
get{ return userName; }
set{ userName = value; }
}
}
}
=====================
using System;
using Gentle.Common;
using Gentle.Framework;
using Gentle.Provider.SQLServer;
using log4net;
using QuickGraph;namespace GentleExample1
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
User ford = new User( 10,"Ford Prefect" ); ford.Persist(); // save the new user and assign an id value User prefect = User.Retrieve( ford.Id ); // retrieve the existing user
}
}
}
为什么显示ford.Persist(); 出现了异常,
未处理的“System.ArgumentNullException”类型的异常出现在 mscorlib.dll 中。其他信息: 键不能为空。是不是我没有配置文件啊,配置文件怎么设置,文档太少了,真是的,还开源哪!