Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- could not initialize a collection: [RealEstateDirectory.Domain.Entities.Dictionaries.District.Streets#65539][SQL: SELECT streets0_."District" as column1_1_, streets0_."Id" as column1_0_0_, streets0_."Name" as column2_0_0_, streets0_."District" as column1_17_0_ FROM "Street" streets0_ WHERE streets0_."District"=?]
- The value "RealEstateDirectory.Domain.Entities.Dictionaries.District" is not of type "RealEstateDirectory.Domain.Entities.Dictionaries.Street" and cannot be used in this generic collection.
- public abstract class Entity<TId>
- {
- public virtual TId Id { get; /*protected*/ set; }
- public override bool Equals(object obj)
- {
- return Equals(obj as Entity<TId>);
- }
- private static bool IsTransient(Entity<TId> obj)
- {
- return obj as object != null &&
- Equals(obj.Id, default(TId));
- }
- protected virtual Type GetUnproxiedType()
- {
- return GetType();
- }
- protected virtual bool Equals(Entity<TId> other)
- {
- if (other as object == null)
- return false;
- if (ReferenceEquals(this, other))
- return true;
- if (!IsTransient(this) &&
- !IsTransient(other) &&
- Equals(Id, other.Id))
- {
- var otherType = other.GetUnproxiedType();
- var thisType = GetUnproxiedType();
- return thisType.IsAssignableFrom(otherType) ||
- otherType.IsAssignableFrom(thisType);
- }
- return false;
- }
- public override int GetHashCode()
- {
- if (Equals(Id, default(TId)))
- return base.GetHashCode();
- return Id.GetHashCode();
- }
- public static bool operator ==(Entity<TId> entity1, Entity<TId> entity2)
- {
- if (entity1 as object == null)
- {
- return (entity2 as object == null);
- }
- else
- {
- return entity1.Equals(entity2);
- }
- }
- public static bool operator !=(Entity<TId> object1, Entity<TId> object2)
- {
- return !(object1 == object2);
- }
- public virtual T As<T>() where T : class
- {
- return this as T;
- }
- public virtual bool Is<T>() where T : class
- {
- return this is T;
- }
- }
- public abstract class BaseDictionary : Entity<int>
- {
- #region Свойства
- public virtual string Name { get; set; }
- #endregion
- #region Конструкторы
- protected BaseDictionary()
- {
- }
- public BaseDictionary(string name)
- {
- Name = name;
- }
- #endregion
- }
- public class District : BaseDictionary
- {
- /// <summary>
- /// Streets in district
- /// </summary>
- public virtual IList<Street> Streets { get; set; }
- protected District()
- {
- }
- public District(string name)
- : base(name)
- {
- }
- }
- public class Street : BaseDictionary
- {
- public virtual District District { get; set; }
- protected Street()
- {
- }
- public Street(string name, District district)
- : base(name)
- {
- District = district;
- }
- }
- public class BaseDictionaryMap : ClassMapping<BaseDictionary>
- {
- public BaseDictionaryMap()
- {
- Id(x => x.Id, m => m.Generator(Generators.HighLow));
- Property(x => x.Name, m=>
- {
- m.NotNullable(true);
- m.Length(2048);
- m.Unique(true);
- });
- }
- }
- public class StreetMap : UnionSubclassMapping<Street>
- {
- public StreetMap()
- {
- ManyToOne(x => x.District, r =>
- {
- r.Cascade(Cascade.All | Cascade.None | Cascade.Persist | Cascade.Remove);
- r.Update(true);
- r.Insert(true);
- r.NotNullable(true);
- //r.Class(typeof(District));
- });
- }
- }
- public class DistrictMap : UnionSubclassMapping<District>
- {
- public DistrictMap()
- {
- Bag(x => x.Streets, c =>
- {
- //c.Inverse(true);
- c.Lazy(CollectionLazy.NoLazy);
- },
- r =>
- {
- r.OneToMany(m =>
- {
- m.Class(typeof (Street));
- }
- );
- }
- );
- }
- }
- public class RepositoryWithTypedIdBase<TId> : IRepositoryWithTypedId<TId>
- {
- public IEnumerable<T> GetAll<T>()
- {
- return CurrentSession.Query<T>().ToList();
- }
- }
- var districtEntities = districtService.GetAll();
Add Comment
Please, Sign In to add comment