This question is locked. New answers and comments are not allowed.
CREATE TABLE hml.Director ( Id INT IDENTITY...)CREATE TABLE DirectorProperty ( DirectorID INT NOT NULL ,PropertyID INT NOT NULL ,DateAdded DATETIME NULL CONSTRAINT DF_DirectorProperty_DateAdded DEFAULT (GETDATE()) ,MainDirector BIT NOT NULL CONSTRAINT DirectorProperty_MainDirector_DF DEFAULT (0) ,CONSTRAINT PK_DirectorProperty PRIMARY KEY CLUSTERED (DirectorID, PropertyID) ,CONSTRAINT FK_DirectorProperty_Director FOREIGN KEY (DirectorID) REFERENCES Director (Id) ON DELETE CASCADE ,CONSTRAINT FK_DirectorProperty_PROPERTY FOREIGN KEY (PropertyID) REFERENCES PROPERTY (PKEY))
public class PMSDirectorProperty { public static MappingConfiguration GetMapping() { var cfg = new MappingConfiguration<PMSDirectorProperty>(); PMSMetadataSource.SetDefaultFiledNamingRules(cfg); cfg.MapType(m => new { m.DirectorId, m.PropertyId }).ToTable("DirectorProperty"); cfg.HasIdentity(c => c.DirectorId); cfg.HasIdentity(c => c.PropertyId); cfg.HasAssociation(c => c.Property).ToColumn("PropertyID"); cfg.HasAssociation(c => c.Director).ToColumn("DirectorID"); return cfg; } public int DirectorId { get; private set; } public int PropertyId { get; private set; } public DateTime? DateAdded { get; set; } public bool MainDirector { get; set; } public PMSDirector Director { get; set; } public PMSProperty Property { get; set; } }public class PMSDirector : GUIObject { public static MappingConfiguration GetMapping() { var cfg = new MappingConfiguration<PMSDirector>(); PMSMetadataSource.SetDefaultFiledNamingRules(cfg); cfg.MapType().UseDefaultMap().ToTable("Director"); cfg.HasProperty(c => c.Id).IsIdentity(KeyGenerator.Autoinc); cfg.HasAssociation(c => c.PreferedContactMethodID).ToColumn("PreferedContactMethodID"); cfg.HasAssociation(c => c.RMCContact).ToColumn("RMCContactID"); cfg.HasAssociation(c => c.Tenants).MapJoinTable("DirectorTenant", (director, tenant) => new { TKEY = tenant.Tkey, DirectorID = director.Id }); cfg.HasAssociation(c => c.DirectorProperties).MapJoinTable("DirectorProperty", (director, property) => new { PropertyID = property.PropertyId, DirectorID = director.Id }); cfg.HasProperty(c => c.AddressIsSpecified).AsTransient(); cfg.HasProperty(c => c.IsTenant).AsTransient(); cfg.HasProperty(c => c.PCShareDirector).AsTransient(); return cfg; }...}
Getting a run-time exception on trying to get a PMSDirector from the database:
Telerik.OpenAccess.Exceptions.MetadataException : The field '<value>' of class 'DataDomain.Property.PMSDirector' must use nested db-column extensions in a db-ref extension as the class 'DataDomain.Property.PMSDirectorProperty' has a composite primary key. --> FromMetadataContainer/namespace[DataDomain.Property]/class[PMSDirector]/field[<DirectorProperties>k__BackingField]/collection/db-link-table/db-value/db-column