NHibernate 映射多对多列表未正确加载对象
我正在尝试在我的一个对象中创建多对多列表。
我尝试通过 NHibernate 保存和加载三个类:Intersection、Vehicle 和 Zone。 Intersection 和 Vehicle 均源自 Device。
Intersection类包含一个Zone列表,每个Zone可能只属于1个Intersection,但每个Intersection可以包含多个Zone。我已经正确映射了它,并且它很好地保存了区域与交叉点的多对一关联。
Vehicle 类包含区域列表。车辆可能属于多个区域。此外,区域还包含车辆列表。每个区域可以包含多辆车辆。这样两者之间就形成了多对多的关系。
所有对象似乎都已正确保存到数据库中。我可以浏览我的表格,并且每个交叉路口、车辆和区域的所有字段都正确传播;但是,当我使用 NHibernate 加载对象时,它们不会加载字段。
我希望有人能够阐明这里可能出了什么问题。
这是我的设备映射,其中包括交叉点和车辆类映射:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class xmlns="urn:nhibernate-mapping-2.2" name="EMTRAC.Devices.Device, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="`Device`" lazy="false">
<id name="PK" type="System.Int64, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="PK" />
<generator class="identity" />
</id>
<many-to-one class="EMTRAC.Connections.Connection, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="LocalConnection" lazy="false" cascade="all">
<column name="LocalConnection_id" />
</many-to-one>
<many-to-one class="EMTRAC.Connections.Connection, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="Connection" lazy="false" cascade="all">
<column name="Connection_id" />
</many-to-one>
<many-to-one class="EMTRAC.Packets.Packet, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="Configuration" lazy="false" cascade="all">
<column name="Configuration_id" />
</many-to-one>
<joined-subclass name="EMTRAC.Intersections.Intersection, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" lazy="false">
<key>
<column name="Device_id" />
</key>
<component name="Zones" access="property">
<bag name="_list" cascade="all-delete-orphan" access="field" lazy="false" fetch="join">
<key>
<column name="Zone_PK" />
</key>
<many-to-many class="EMTRAC.Zones.Zone, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</bag>
</component>
<many-to-one class="EMTRAC.Intersections.Streets, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="Streets" lazy="false" cascade="all">
<column name="Streets_id" />
</many-to-one>
<many-to-one class="EMTRAC.Positions.Position, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="Position" lazy="false" cascade="all">
<column name="Position" />
</many-to-one>
</joined-subclass>
<joined-subclass name="EMTRAC.Vehicles.Vehicle, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<key>
<column name="Device_id" />
</key>
<component name="Zones" access="property">
<bag name="_list" cascade="all-delete-orphan" access="field" lazy="false" table="VehicleZones" inverse="false">
<key>
<column name="Vehicle_PK" />
</key>
<many-to-many class="EMTRAC.Zones.Zone, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</bag>
</component>
<property name="Active" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Active" />
</property>
<property name="Status" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Status" />
</property>
<property name="Velocity" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Velocity" />
</property>
<property name="Heading" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Heading" />
</property>
<property name="Agency" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Agency" />
</property>
<property name="Unit" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Unit" />
</property>
<property name="Priority" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Priority" />
</property>
<many-to-one class="EMTRAC.Positions.Position, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="Position" lazy="false" cascade="all">
<column name="Position_id" />
</many-to-one>
<many-to-one class="EMTRAC.VehicleClasses.VehicleClass, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="VehClass" lazy="false" cascade="all">
<column name="VehClass_id" />
</many-to-one>
</joined-subclass>
</class>
</hibernate-mapping>
这是我的区域类映射:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class xmlns="urn:nhibernate-mapping-2.2" name="EMTRAC.Zones.Zone, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="`Zone`" lazy="false">
<id name="ID" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="PK" />
<generator class="identity" />
</id>
<property name="Active" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Active" />
</property>
<property name="Dir" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Dir" />
</property>
<property name="IntID" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="IntID" />
</property>
<property name="Width" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Width" />
</property>
<property name="Distance" type="System.Double, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Distance" />
</property>
<many-to-one class="EMTRAC.Headings.Heading, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="Heading" cascade="all-delete-orphan">
<column name="Heading_id" />
</many-to-one>
<many-to-one class="EMTRAC.Positions.Position, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="Start" cascade="all-delete-orphan">
<column name="Start_id" />
</many-to-one>
<many-to-one class="EMTRAC.Positions.Position, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="Finish" cascade="all-delete-orphan">
<column name="Finish_id" />
</many-to-one>
<component name="Vehicles" access="property">
<bag name="_list" cascade="all-delete-orphan" access="field" lazy="false" table="ZoneVehicles" fetch="join" inverse="true">
<key>
<column name="Zone_PK" />
</key>
<many-to-many class="EMTRAC.Vehicles.Vehicle, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</bag>
</component>
</class>
</hibernate-mapping>
最后,这是我的车辆和区域类:
public class Vehicle : Device
{
#region Fields
protected bool active;
protected int id;
protected Position position = new Position();
protected int status;
protected VehicleClass vehClass;
protected int velocity;
protected int heading;
protected string agency;
protected string unit;
protected int priority;
private ZoneCollection zones = new ZoneCollection();
#endregion
#region Properties
[Browsable(false)]
public virtual long PK { get; set; }
[Browsable(false)]
public virtual bool Active
{
get { return active; }
set { active = value; }
}
[CategoryAttribute("Configuration"),
DescriptionAttribute("Vehicle Identification Number")]
public virtual int ID
{
get { return id; }
set { id = value; }
}
[Browsable(false)]
public virtual Position Position
{
get { return position; }
set { position = value; }
}
[Browsable(false)]
public virtual int Status
{
get { return status; }
set { status = value; }
}
[CategoryAttribute("Configuration"),
DescriptionAttribute("This is the type of vehicle.")]
public virtual VehicleClass VehClass
{
get { return vehClass; }
set { vehClass = value; }
}
[Browsable(false)]
public virtual int Velocity
{
get { return velocity; }
set { velocity = value; }
}
[Browsable(false)]
public virtual int Heading
{
get { return heading; }
set { heading = value; }
}
[CategoryAttribute("Configuration"),
DescriptionAttribute("This is the name of the city agency that owns the vehicle.")]
public virtual string Agency
{
get { return agency; }
set { agency = value; }
}
[CategoryAttribute("Configuration"),
DescriptionAttribute("This is the ID number assigned to the vehicle by the city or agency and is also used for identification purposes. This field accepts both alpha and numeric entries.")]
public virtual string Unit
{
get { return unit; }
set { unit = value; }
}
[CategoryAttribute("Configuration"),
DescriptionAttribute("This is the priority level that the vehicle has over other vehicles with priority control capabilities (1 being the highest, 5 being the lowest). This is not the same as the priority control levels assigned to emergency vehicles (priority 1 for EVP) and mass-transit vehicles (priority 2 for TSP).")]
public virtual int Priority
{
get { return priority; }
set { priority = value; }
}
[CategoryAttribute("Configuration"),
DescriptionAttribute("Zones associated with the Vehicle.")]
[System.ComponentModel.Browsable(true)]
[System.ComponentModel.Editor(typeof(VehicleCollectionModalEditor), typeof(System.Drawing.Design.UITypeEditor))]
public virtual ZoneCollection Zones
{
get { return zones; }
set { zones = value; }
}
[Browsable(false)]
public virtual string IPLocal
{
get
{
if (LocalConnection.GetType() == typeof(Connections.ConnectionSerial))
{
return (
((Connections.ConnectionSerial)LocalConnection).SerialConn.PortName + " :: " +
((Connections.ConnectionSerial)LocalConnection).SerialConn.BaudRate.ToString()
);
}
else if (LocalConnection.GetType() == typeof(Connections.ConnectionTCP))
{
return (
((IPEndPoint)((Connections.ConnectionTCP)LocalConnection).Client.Client.RemoteEndPoint).Address.ToString() + " :: " +
((IPEndPoint)((Connections.ConnectionTCP)LocalConnection).Client.Client.RemoteEndPoint).Port.ToString()
);
}
else
{
return string.Empty;
}
}
}
[Browsable(false)]
public virtual string IPNetwork
{
get
{
if (Connection.GetType() == typeof(Connections.ConnectionSerial))
{
return (
((Connections.ConnectionSerial)Connection).SerialConn.PortName + " :: " +
((Connections.ConnectionSerial)Connection).SerialConn.BaudRate.ToString()
);
}
else if (Connection.GetType() == typeof(Connections.ConnectionTCP))
{
return (
((IPEndPoint)((Connections.ConnectionTCP)Connection).Client.Client.RemoteEndPoint).Address.ToString() + " :: " +
((IPEndPoint)((Connections.ConnectionTCP)Connection).Client.Client.RemoteEndPoint).Port.ToString()
);
}
else
{
return string.Empty;
}
}
}
#endregion
}
public class Zone
{
#region Private Fields
private bool active;
private string dir;
private Heading heading = new Heading();
private int id;
private int intID;
private Position start = new Position();
private Position finish = new Position();
private int width;
private Position[] corners = new Position[4];
private Streets streets = new Streets();
private VehicleCollection vehicles = new VehicleCollection();
private double distance;
#endregion
#region Constructors
public Zone()
{
if (Program.main != null)
{
IntID = Program.main.intID;
Intersection intersection = Program.data.Intersections.list.Find(
delegate(Intersection tInt)
{
return tInt.ID == IntID;
}
);
if (intersection != null)
{
Streets.Crossing = intersection.Streets.Crossing;
Streets.Route = intersection.Streets.Route;
}
}
}
#endregion
#region Properties
[Browsable(false)]
public virtual long PK { get; set; }
[Browsable(false)]
public virtual bool Active
{
get { return active; }
set { active = value; }
}
[CategoryAttribute("Configuration"),
DescriptionAttribute("The direction for the Zone.")]
public virtual string Dir
{
get { return dir; }
set { dir = value; }
}
[CategoryAttribute("Configuration"),
DescriptionAttribute("This is the amount of heading variance (clockwise and counter-clockwise) in actual degrees.")]
public virtual Heading Heading
{
get { return heading; }
set { heading = value; }
}
[CategoryAttribute("Configuration"),
DescriptionAttribute("The Zone Identification Number.")]
public virtual int ID
{
get { return id; }
set { id = value; }
}
[CategoryAttribute("Configuration"),
DescriptionAttribute("The Identification Number associated with the Priority Detector of the Zone.")]
public virtual int IntID
{
get { return intID; }
set { intID = value; }
}
[CategoryAttribute("Position"),
DescriptionAttribute("The location of the Zone's Start.")]
public virtual Position Start
{
get { return start; }
set { start = value; }
}
[CategoryAttribute("Position"),
DescriptionAttribute("The location of the Zone's Finish.")]
public virtual Position Finish
{
get { return finish; }
set { finish = value; }
}
[CategoryAttribute("Configuration"),
DescriptionAttribute("The width of the Zone.")]
public virtual int Width
{
get { return width; }
set { width = value; }
}
[CategoryAttribute("Configuration"),
DescriptionAttribute("The distance of the Zone.")]
public virtual double Distance
{
get { return distance; }
set { distance = value; }
}
[Browsable(false)]
public virtual Position[] Corners
{
get { return corners; }
set { corners = value; }
}
[CategoryAttribute("Configuration"),
DescriptionAttribute("The streets associated with the Zone."),
DisplayName("Zone Streets")]
public virtual Streets Streets
{
get { return streets; }
set { streets = value; }
}
[CategoryAttribute("Configuration"),
DescriptionAttribute("Vehicles associated with the Zone.")]
[System.ComponentModel.Browsable(true)]
[System.ComponentModel.Editor(typeof(VehicleCollectionModalEditor), typeof(System.Drawing.Design.UITypeEditor))]
public virtual VehicleCollection Vehicles
{
get { return vehicles; }
set { vehicles = value; }
}
#endregion
}
我确信这可能是我缺少的一些非常小的东西。有什么想法吗?
I am attempting a many-to-many list in one of my objects.
I have three classes which I am attempting to save and load via NHibernate: Intersection, Vehicle and Zone. Intersection and Vehicle are both derived from Device.
The Intersection class contains a list of Zones, which each zone may only belong to 1 Intersection, but each Intersection may contain multiple Zones. I have this mapped correctly and it is saving the many-to-one association of Zones to the Intersections just fine.
The Vehicle class contains a List of Zones. The Vehicle may belong to multiple Zones. Also, the Zones contain a List of Vehicles. Each Zone may contain multiple Vehicles. Thus the many-to-many relationship between the two.
All the objects appear to be saved to the database correctly. I can go through my tables and all the fields for each Intersection, Vehicle, and Zone are propagated correctly; however, they are not loading the fields when I load the object using NHibernate.
I am hoping someone may be able to shed some light as to what may be going wrong here.
Here is my mapping of Device which includes the Intersection and Vehicle class mappings:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class xmlns="urn:nhibernate-mapping-2.2" name="EMTRAC.Devices.Device, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="`Device`" lazy="false">
<id name="PK" type="System.Int64, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="PK" />
<generator class="identity" />
</id>
<many-to-one class="EMTRAC.Connections.Connection, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="LocalConnection" lazy="false" cascade="all">
<column name="LocalConnection_id" />
</many-to-one>
<many-to-one class="EMTRAC.Connections.Connection, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="Connection" lazy="false" cascade="all">
<column name="Connection_id" />
</many-to-one>
<many-to-one class="EMTRAC.Packets.Packet, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="Configuration" lazy="false" cascade="all">
<column name="Configuration_id" />
</many-to-one>
<joined-subclass name="EMTRAC.Intersections.Intersection, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" lazy="false">
<key>
<column name="Device_id" />
</key>
<component name="Zones" access="property">
<bag name="_list" cascade="all-delete-orphan" access="field" lazy="false" fetch="join">
<key>
<column name="Zone_PK" />
</key>
<many-to-many class="EMTRAC.Zones.Zone, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</bag>
</component>
<many-to-one class="EMTRAC.Intersections.Streets, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="Streets" lazy="false" cascade="all">
<column name="Streets_id" />
</many-to-one>
<many-to-one class="EMTRAC.Positions.Position, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="Position" lazy="false" cascade="all">
<column name="Position" />
</many-to-one>
</joined-subclass>
<joined-subclass name="EMTRAC.Vehicles.Vehicle, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<key>
<column name="Device_id" />
</key>
<component name="Zones" access="property">
<bag name="_list" cascade="all-delete-orphan" access="field" lazy="false" table="VehicleZones" inverse="false">
<key>
<column name="Vehicle_PK" />
</key>
<many-to-many class="EMTRAC.Zones.Zone, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</bag>
</component>
<property name="Active" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Active" />
</property>
<property name="Status" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Status" />
</property>
<property name="Velocity" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Velocity" />
</property>
<property name="Heading" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Heading" />
</property>
<property name="Agency" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Agency" />
</property>
<property name="Unit" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Unit" />
</property>
<property name="Priority" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Priority" />
</property>
<many-to-one class="EMTRAC.Positions.Position, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="Position" lazy="false" cascade="all">
<column name="Position_id" />
</many-to-one>
<many-to-one class="EMTRAC.VehicleClasses.VehicleClass, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="VehClass" lazy="false" cascade="all">
<column name="VehClass_id" />
</many-to-one>
</joined-subclass>
</class>
</hibernate-mapping>
And here is my mapping of the Zone class:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class xmlns="urn:nhibernate-mapping-2.2" name="EMTRAC.Zones.Zone, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="`Zone`" lazy="false">
<id name="ID" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="PK" />
<generator class="identity" />
</id>
<property name="Active" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Active" />
</property>
<property name="Dir" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Dir" />
</property>
<property name="IntID" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="IntID" />
</property>
<property name="Width" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Width" />
</property>
<property name="Distance" type="System.Double, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Distance" />
</property>
<many-to-one class="EMTRAC.Headings.Heading, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="Heading" cascade="all-delete-orphan">
<column name="Heading_id" />
</many-to-one>
<many-to-one class="EMTRAC.Positions.Position, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="Start" cascade="all-delete-orphan">
<column name="Start_id" />
</many-to-one>
<many-to-one class="EMTRAC.Positions.Position, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="Finish" cascade="all-delete-orphan">
<column name="Finish_id" />
</many-to-one>
<component name="Vehicles" access="property">
<bag name="_list" cascade="all-delete-orphan" access="field" lazy="false" table="ZoneVehicles" fetch="join" inverse="true">
<key>
<column name="Zone_PK" />
</key>
<many-to-many class="EMTRAC.Vehicles.Vehicle, EMTRAC_v3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</bag>
</component>
</class>
</hibernate-mapping>
And finally here are my Vehicle and Zone classes:
public class Vehicle : Device
{
#region Fields
protected bool active;
protected int id;
protected Position position = new Position();
protected int status;
protected VehicleClass vehClass;
protected int velocity;
protected int heading;
protected string agency;
protected string unit;
protected int priority;
private ZoneCollection zones = new ZoneCollection();
#endregion
#region Properties
[Browsable(false)]
public virtual long PK { get; set; }
[Browsable(false)]
public virtual bool Active
{
get { return active; }
set { active = value; }
}
[CategoryAttribute("Configuration"),
DescriptionAttribute("Vehicle Identification Number")]
public virtual int ID
{
get { return id; }
set { id = value; }
}
[Browsable(false)]
public virtual Position Position
{
get { return position; }
set { position = value; }
}
[Browsable(false)]
public virtual int Status
{
get { return status; }
set { status = value; }
}
[CategoryAttribute("Configuration"),
DescriptionAttribute("This is the type of vehicle.")]
public virtual VehicleClass VehClass
{
get { return vehClass; }
set { vehClass = value; }
}
[Browsable(false)]
public virtual int Velocity
{
get { return velocity; }
set { velocity = value; }
}
[Browsable(false)]
public virtual int Heading
{
get { return heading; }
set { heading = value; }
}
[CategoryAttribute("Configuration"),
DescriptionAttribute("This is the name of the city agency that owns the vehicle.")]
public virtual string Agency
{
get { return agency; }
set { agency = value; }
}
[CategoryAttribute("Configuration"),
DescriptionAttribute("This is the ID number assigned to the vehicle by the city or agency and is also used for identification purposes. This field accepts both alpha and numeric entries.")]
public virtual string Unit
{
get { return unit; }
set { unit = value; }
}
[CategoryAttribute("Configuration"),
DescriptionAttribute("This is the priority level that the vehicle has over other vehicles with priority control capabilities (1 being the highest, 5 being the lowest). This is not the same as the priority control levels assigned to emergency vehicles (priority 1 for EVP) and mass-transit vehicles (priority 2 for TSP).")]
public virtual int Priority
{
get { return priority; }
set { priority = value; }
}
[CategoryAttribute("Configuration"),
DescriptionAttribute("Zones associated with the Vehicle.")]
[System.ComponentModel.Browsable(true)]
[System.ComponentModel.Editor(typeof(VehicleCollectionModalEditor), typeof(System.Drawing.Design.UITypeEditor))]
public virtual ZoneCollection Zones
{
get { return zones; }
set { zones = value; }
}
[Browsable(false)]
public virtual string IPLocal
{
get
{
if (LocalConnection.GetType() == typeof(Connections.ConnectionSerial))
{
return (
((Connections.ConnectionSerial)LocalConnection).SerialConn.PortName + " :: " +
((Connections.ConnectionSerial)LocalConnection).SerialConn.BaudRate.ToString()
);
}
else if (LocalConnection.GetType() == typeof(Connections.ConnectionTCP))
{
return (
((IPEndPoint)((Connections.ConnectionTCP)LocalConnection).Client.Client.RemoteEndPoint).Address.ToString() + " :: " +
((IPEndPoint)((Connections.ConnectionTCP)LocalConnection).Client.Client.RemoteEndPoint).Port.ToString()
);
}
else
{
return string.Empty;
}
}
}
[Browsable(false)]
public virtual string IPNetwork
{
get
{
if (Connection.GetType() == typeof(Connections.ConnectionSerial))
{
return (
((Connections.ConnectionSerial)Connection).SerialConn.PortName + " :: " +
((Connections.ConnectionSerial)Connection).SerialConn.BaudRate.ToString()
);
}
else if (Connection.GetType() == typeof(Connections.ConnectionTCP))
{
return (
((IPEndPoint)((Connections.ConnectionTCP)Connection).Client.Client.RemoteEndPoint).Address.ToString() + " :: " +
((IPEndPoint)((Connections.ConnectionTCP)Connection).Client.Client.RemoteEndPoint).Port.ToString()
);
}
else
{
return string.Empty;
}
}
}
#endregion
}
public class Zone
{
#region Private Fields
private bool active;
private string dir;
private Heading heading = new Heading();
private int id;
private int intID;
private Position start = new Position();
private Position finish = new Position();
private int width;
private Position[] corners = new Position[4];
private Streets streets = new Streets();
private VehicleCollection vehicles = new VehicleCollection();
private double distance;
#endregion
#region Constructors
public Zone()
{
if (Program.main != null)
{
IntID = Program.main.intID;
Intersection intersection = Program.data.Intersections.list.Find(
delegate(Intersection tInt)
{
return tInt.ID == IntID;
}
);
if (intersection != null)
{
Streets.Crossing = intersection.Streets.Crossing;
Streets.Route = intersection.Streets.Route;
}
}
}
#endregion
#region Properties
[Browsable(false)]
public virtual long PK { get; set; }
[Browsable(false)]
public virtual bool Active
{
get { return active; }
set { active = value; }
}
[CategoryAttribute("Configuration"),
DescriptionAttribute("The direction for the Zone.")]
public virtual string Dir
{
get { return dir; }
set { dir = value; }
}
[CategoryAttribute("Configuration"),
DescriptionAttribute("This is the amount of heading variance (clockwise and counter-clockwise) in actual degrees.")]
public virtual Heading Heading
{
get { return heading; }
set { heading = value; }
}
[CategoryAttribute("Configuration"),
DescriptionAttribute("The Zone Identification Number.")]
public virtual int ID
{
get { return id; }
set { id = value; }
}
[CategoryAttribute("Configuration"),
DescriptionAttribute("The Identification Number associated with the Priority Detector of the Zone.")]
public virtual int IntID
{
get { return intID; }
set { intID = value; }
}
[CategoryAttribute("Position"),
DescriptionAttribute("The location of the Zone's Start.")]
public virtual Position Start
{
get { return start; }
set { start = value; }
}
[CategoryAttribute("Position"),
DescriptionAttribute("The location of the Zone's Finish.")]
public virtual Position Finish
{
get { return finish; }
set { finish = value; }
}
[CategoryAttribute("Configuration"),
DescriptionAttribute("The width of the Zone.")]
public virtual int Width
{
get { return width; }
set { width = value; }
}
[CategoryAttribute("Configuration"),
DescriptionAttribute("The distance of the Zone.")]
public virtual double Distance
{
get { return distance; }
set { distance = value; }
}
[Browsable(false)]
public virtual Position[] Corners
{
get { return corners; }
set { corners = value; }
}
[CategoryAttribute("Configuration"),
DescriptionAttribute("The streets associated with the Zone."),
DisplayName("Zone Streets")]
public virtual Streets Streets
{
get { return streets; }
set { streets = value; }
}
[CategoryAttribute("Configuration"),
DescriptionAttribute("Vehicles associated with the Zone.")]
[System.ComponentModel.Browsable(true)]
[System.ComponentModel.Editor(typeof(VehicleCollectionModalEditor), typeof(System.Drawing.Design.UITypeEditor))]
public virtual VehicleCollection Vehicles
{
get { return vehicles; }
set { vehicles = value; }
}
#endregion
}
I'm sure it is probably something really small I am missing. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1)您的多对多表缺少外键定义。外键会由NH生成,但双方必须相同,所以不起作用。
例如。
2)使用
fetch="join"
映射包,这不是一个好主意。1) your many-to-many tables a missing a foreign key definition. The foreign key will be generated by NH, but it must be the same for both sides, so it doesn't work.
eg.
2) The bags are mapped using
fetch="join"
which isn't a good idea.