http://dataobjects.net/“rel=“nofollow noretinger”>DataObjects.Net。 它将这样做。 现在没有任何绘图档案,因为数据库图象自动由人力资源管理厅生成,包括问答关系的附属表格。
4. 食堂:
[HierachyRoot]
public class Tag : Entity
{
[Field, Key]
public int Id { get; private set; }
[Field(Length = 100, Indexed = true)]
public string Name { get; private set; }
[Field]
public int QuestionsCount { get; set; }
public Tag(string name)
{
Name = name;
}
}
问题类别:
[HierachyRoot]
public class Question : Entity
{
[Field, Key]
public int Id { get; private set; }
[Field]
public EntitySet<Tag> Tags { get; private set; }
// Business methods (can be placed in separate service class)
public void AddTag(string name)
{
var tag = Query.All<Tag>().SingleOrDefault(t => t.Name == name);
if (tag==null)
tag = new Tag(name) { QuestionsCount = 1 }
else
tag.QuestionsCount++;
Tags.Add(tag);
}
public void RemoveTag(string name)
{
var tag = Query.All<Tag>.Single(t => t.Name == name);
tag.QuestionsCount--;
Tags.Remove(tag);
}
}
申请代码:
using (Session.Open())
using (var transactionScope = Transaction.Open())
{
var question = Query.Single<Question>(questionId);
question.RemoveTag("tag1");
question.RemoveTag("tag2");
question.AddTag("tag3");
question.AddTag("tag4");
transactionScope.Complete();
}