gpt4 book ai didi

NHibernate.QueryException : could not resolve property

转载 作者:行者123 更新时间:2023-12-04 06:50:15 31 4
gpt4 key购买 nike

我正在使用 FluentNHibernate 和 Linq To Nhibernate,以及这些实体(仅相关部分):

public class Player : BaseEntity<Player>
{
private readonly IList<PlayerInTeam> allTeams = new List<PlayerInTeam>();

public IEnumerable<Team> Teams
{
get
{
return from playerInTeam in allTeams
where playerInTeam.Roster.Match == null
select playerInTeam.Roster.Team;
}
}
}

public class PlayerInTeam : BaseEntity<PlayerInTeam>
{
public int PlayerNumber { get; set; }
public Player Player { get; set; }
public Position Position { get; set; }
public Roster Roster { get; set; }
}

public class Roster : BaseEntity<Roster>
{
private readonly IList<PlayerInTeam> players = new List<PlayerInTeam>();

public Team Team { get; set; }
public IEnumerable<PlayerInTeam> Players { get { return players; } }
}

public class Team : BaseEntity<Team>
{
private readonly IList<Roster> allRosters = new List<Roster>();

public Team(string name, Sex sex)
{
allRosters.Add(new Roster(this));
}

public Roster DefaultRoster
{
get { return allRosters.Where(r => r.Match == null).First(); }
}
}

和匹配的映射:
public class PlayerMap : ClassMap<Player>
{
public PlayerMap()
{
HasMany<PlayerInTeam>(Reveal.Member<Player>("allTeams"))
.Inverse()
.Cascade.AllDeleteOrphan()
.Access.CamelCaseField();
}
}

public class PlayerInTeamMap : ClassMap<PlayerInTeam>
{
public PlayerInTeamMap()
{
References(pit => pit.Player)
.Not.Nullable();

References(pit => pit.Roster)
.Not.Nullable();
}
}

public class RosterMap : ClassMap<Roster>
{
public RosterMap()
{
References(tr => tr.Team)
.Not.Nullable();

HasMany<PlayerInTeam>(Reveal.Member<Roster>("players"))
.Inverse()
.Cascade.AllDeleteOrphan()
.Access.CamelCaseField();
}
}

public class TeamMap : ClassMap<Team>
{
public TeamMap()
{
HasMany<Roster>(Reveal.Member<Team>("allRosters"))
.Inverse()
.Cascade.AllDeleteOrphan()
.Access.CamelCaseField();
}
}

我有这个存储库方法:
public IEnumerable<Player> PlayersNotInTeam(Team team)
{
return from player in Session.Linq<Player>()
where !player.Teams.Contains(team)
select player;
}

这给了我这个异常(exception):NHibernate.QueryException:无法解析属性:团队:Emidee.CommonEntities.Player [.Where(NHibernate.Linq.NhQueryable`1[Emidee.CommonEntities.Player], Quote((player, ) => (Not(.Contains(player.Teams, p1, )))), )]

我查看了由 Fluent NHibernate 生成的关于 Player 的 hbm 文件,这是我得到的:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property" auto-import="true" default-cascade="none" default-lazy="true">
<class xmlns="urn:nhibernate-mapping-2.2" mutable="true" name="Emidee.CommonEntities.Player, Emidee.CommonEntities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=65c7ad487c784bec" table="Players">
<id name="Id" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Id" />
<generator class="increment" />
</id>
<bag access="field.camelcase" cascade="all-delete-orphan" inverse="true" name="allTeams" mutable="true">
<key>
<column name="Player_id" not-null="true" />
</key>
<one-to-many class="Emidee.CommonEntities.PlayerInTeam, Emidee.CommonEntities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=65c7ad487c784bec" />
</bag>
</class>
</hibernate-mapping>

实际上,我在该文件中没有 Player 的 Teams 属性。

但是我的映射不应该处理这个吗?
你认为问题出在哪里?

提前致谢

麦克风

最佳答案

从技术上讲,不可能在 C-sharp 中查看方法体的内部。所以 FluentNhibernate 也不能这样做。您必须应用不同的策略来为实体建模和/或自己生成映射。

关于NHibernate.QueryException : could not resolve property,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3229436/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com