当我运行此代码时,List 方法会导致 Developer 刷新。我不希望这种情况发生。
Developer developer = null;
IEnumerable<Language> languages = null;
using (var session = this.SessionFactory.OpenSession())
using (var trx = session.BeginTransaction())
{
developer = session.Get<Developer>(id);
languages = session.CreateCriteria<Language>().List<Language>();
}
如果我交换其中的行using
以便首先检索语言,则不会刷新开发人员。但我不想记住这样做,除非有充分的理由。
我需要更改我的映射吗?这是它现在的样子:
class DeveloperMap : ClassMap<Developer>
{
public DeveloperMap()
{
Table("Developers");
Id(x => x.Id).GeneratedBy.Identity();
Map(x => x.FirstName);
Map(x => x.LastName);
References(x => x.FavoriteLanguage).Cascade.None();
HasManyToMany(x => x.AssignedProjects)
.Cascade.None()
.Table("DevelopersProjects")
.FetchType.Join();
}
}
这里也是 Developer 类,以防万一。
public class Developer
{
public virtual int? Id { get; set; }
public virtual string FirstName { get; set; }
public virtual string LastName { get; set; }
public virtual Language FavoriteLanguage { get; set; }
public virtual IList<Project> AssignedProjects { get; protected internal set; }
}