下载地址:
https://sourceforge.net/project/showfiles.php?group_id=165914
本次更新内容应该比较令人值得期待:
1、更全面的自增长主键支持。现在即使是有继承关系的实体,也可以设置自增长主键了。
2、自动Guid主键支持。原来,如果使用Guid作主键,必须手动设置新建实体的主键值。在新版本中,如果使用Guid主键,如果没有为主键设置值,NBear会在Save时自动为它生成一个值。因此,您将能和int自增长字段类似使用Guid主键的实体。
3、自动设置关联属性。原来的版本中,如果Profile是User的属性,但是,Profile包含一个UserID外键属性,则保存user前需要手动设置Profile的UserID为当前user的ID;在新版本中,这样的关联属性无需再手动设置,凡是设置到User的对象,save user时,这些关联属性会自动从user中获取。
只设置get吗?还是get,set都要?
有错误啊,定义如下
public interface User : Entity
{
[PrimaryKey]
int ID
{
get;
}
public User CreatNewUser()
{
WriteLine("Create a new user and set property values.");
Entities.User user = new Entities.User();
UserName name = new UserName();
name.FirstName = "MK2";
name.LastName = "Feng";
UserProfile profile = new UserProfile();
//profile.UserID = user.ID;
profile.LastIP = "00000";
profile.Content = "mk2profile";
user.Profile = profile;
user.Name = name;
user.Birthday = DateTime.Now;
user.Email = "fen...@gmail.com";
user.LogOnCount = 0;
user.LogOnDate = DateTime.Now;
user.LogOnName = "fengmk2";
user.No = "333";
user.PassAnswer = "ddd";
user.PassQuestion = "kkk";
user.Password = "222";
user.Status = UserStatus.Availate;
return user;
}
protected void btnNewUser_Click(object sender, EventArgs e)
{
Entities.User user = CreatNewUser();
gateway.Save<Entities.User>(user);
WriteLine("The found user:");
WriteLine(SerializationManager.Serialize(user));
}
Text INSERT INTO [User] ( [Name], [Email], [Status], [LogOnName],
[Password], [PassQuestion], [PassAnswer], [No], [Sex], [Birthday],
[CreateDate], [LogOnDate], [LogOnCount] ) VALUES ( @Name, @Email,
@Status, @LogOnName, @Password, @PassQuestion, @PassAnswer, @No, @Sex,
@Birthday, @CreateDate, @LogOnDate, @LogOnCount ); SELECT
SCOPE_IDENTITY()
Parameters:
@Name[String] = <?xml version="1.0" encoding="utf-16"?>
<UserName xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<FirstName>MK2</FirstName>
<LastName>Feng</LastName>
</UserName>
@Email[String] = fen...@gmail.com
@Status[Int32] = Availate
@LogOnName[String] = fengmk2
@Password[String] = 222
@PassQuestion[String] = kkk
@PassAnswer[String] = ddd
@No[String] = 333
@Sex[String] =
@Birthday[DateTime] = 2006-11-15 20:08:28
@CreateDate[String] =
@LogOnDate[DateTime] = 2006-11-15 20:08:28
@LogOnCount[Int32] = 0
CREATE TABLE [dbo].[User] (
[ID] int IDENTITY (1, 1) NOT NULL,
[Name] ntext NULL,
[Email] nvarchar(50) NULL,
[Status] int NULL,
[LogOnName] nvarchar(50) NULL,
[Password] nvarchar(50) NULL,
[PassQuestion] nvarchar(100) NULL,
[PassAnswer] nvarchar(100) NULL,
[No] nvarchar(30) NULL,
[Sex] nvarchar(10) NULL,
[Birthday] datetime NULL,
[CreateDate] datetime NULL,
[LogOnDate] datetime NULL,
[LogOnCount] int NULL
) ON [PRIMARY]
GO
我先去试试IoC示例中的,那个好像也是使用int自增的```
`````是不是我太多问题了???
一对一外键关联:这里使用了Profile.UserID做外键。
Text INSERT INTO [UserProfile] ( [Content], [LastIP], [UserID] ) VALUES
( @Content, @LastIP, @UserID ); SELECT SCOPE_IDENTITY()
Parameters:
@Content[String] = mk2profile
@LastIP[String] = 00000
@UserID[Int32] = 1
Serialize(user):
<?xml version="1.0" encoding="utf-16"?>
<User xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ID>1</ID>
<Name>
<FirstName>MK2</FirstName>
<LastName>Feng</LastName>
</Name>
<Email>fen...@gmail.com</Email>
<Profile>
<ID>1</ID>
<Content>mk2profile</Content>
<LastIP>00000</LastIP>
<UserID>1</UserID>
</Profile>
<Groups />
<Roles />
<Tags />
<Contents />
<Comments />
<Categories />
<Status>Availate</Status>
<LogOnName>fengmk2</LogOnName>
<Password>222</Password>
<PassQuestion>kkk</PassQuestion>
<PassAnswer>ddd</PassAnswer>
<Phones />
<No>333</No>
<Birthday>2006-11-16T01:33:26.78125+08:00</Birthday>
<CreateDate xsi:nil="true" />
<LogOnDate>2006-11-16T01:33:26.78125+08:00</LogOnDate>
<LogOnCount>0</LogOnCount>
</User>