non primary key relation

Thread is closed for posting
2 posts, 0 answers
  1. Bernd
    Bernd avatar
    91 posts
    Member since:
    Feb 2013

    Posted 15 Dec 2016 Link to this post

    Hello.

    I have a view, called "OperationAlternative".

    namespace idee5.Dispatcher.Model.DAL {
        public class OperationAlternative {
            [Key]
            public virtual int WorkOrderId {
                get;
                set;
            }
     
            public virtual int? WorkplaceId {
                get;
                set;
            }
     
            /// <summary>
            /// Highest rank means highest efficiency
            /// </summary>
            [Required]
            public virtual char EfficiencyRank {
                get;
                set;
            }
     
            [Key]
            public virtual int OperationId {
                get;
                set;
            }
     
            [Required]
            public virtual uint SequenceNumber {
                get;
                set;
            }
     
            // association properties
            // association:
            public virtual Workplace Workplace {
                get;
                set;
            }
     
            // association: CurrentOperation
            public virtual Operation Operation {
                get;
                set;
            }
     
        }
    }

    This view is referenced by "Operation". A common table.

    namespace idee5.Dispatcher.Model.DAL {
        public partial class Operation : IMasterSystemId {
            [Required(),Key()]
            public virtual int Id {
                get;
                set;
            }
     
            [Required]
            public virtual uint SequenceNumber {
                get;
                set;
            }
     
            /// <summary>
            /// Taktzeit
            /// </summary>
            public virtual float CycleTime {
                get;
                set;
            }
     
            public virtual OperationProcessingStates ProcessingStatus {
                get;
                set;
            }
     
            public virtual float QuantityPerCycle {
                get;
                set;
            }
     
            [Required()]
            public virtual string Description {
                get;
                set;
            }
     
            /// <summary>
            /// Produzierte Menge der Komponente
            /// </summary>
            public virtual float QuantityConfirmed {
                get;
                set;
            }
     
            /// <summary>
            /// Ausschussmenge der Komponente
            /// </summary>
            public virtual float QuantityDefective {
                get;
                set;
            }
     
            /// <summary>
            /// Menge der Komponenten mit verminderter Qualität.
            /// </summary>
            public virtual float QuantityLessQuality {
                get;
                set;
            }
     
            /// <summary>
            /// Rüstzeit
            /// </summary>
            public virtual DateTime SetupTime {
                get;
                set;
            }
     
            /// <summary>
            /// Stückzeit
            /// </summary>
            public virtual DateTime TimePerUnit {
                get;
                set;
            }
     
            /// <summary>
            /// Geplanter Start des Arbeitsgangs
            /// </summary>
            public virtual DateTime? StartScheduled {
                get;
                set;
            }
     
            /// <summary>
            /// Geplantes Ende des Arbeitsgang
            /// </summary>
            public virtual DateTime? EndScheduled {
                get;
                set;
            }
     
            /// <summary>
            /// Tatsächlicher Start des Arbeitsgang
            /// </summary>
            public virtual DateTime? StartActual {
                get;
                set;
            }
     
            /// <summary>
            /// Tatsächliches Ende des Arbeitsgang
            /// </summary>
            public virtual DateTime? EndActual {
                get;
                set;
            }
     
            public virtual int WorkOrderId {
                get;
                set;
            }
     
            public virtual int? CycleTimeUoM {
                get;
                set;
            }
     
            public virtual int? WorkplaceId {
                get;
                set;
            }
     
            public virtual int? OperatingResourceId {
                get;
                set;
            }
     
            /// <summary>
            /// Berechneter Start des Arbeitsgang
            /// </summary>
            public virtual DateTime? StartCalculated {
                get;
                set;
            }
     
            /// <summary>
            /// Highest rank means highest efficiency
            /// </summary>
            [Required]
            public virtual char EfficiencyRank {
                get;
                set;
            }
     
            /// <summary>
            /// Liefezeit nach Arbeitsgang
            /// </summary>
            public virtual DateTime WaitTimeAfter {
                get;
                set;
            }
     
            public virtual DateTime? EarliestStart {
                get;
                set;
            }
     
            public virtual DateTime? LatestEnd {
                get;
                set;
            }
     
            /// <summary>
            /// false if the operation has changes, not synchronized with the master system
            /// </summary>
            public virtual bool IsSynchronized {
                get;
                set;
            }
     
            // Implementation of IMasterSystemId
            /// <summary>
            /// Master systems hierarchical identification. E.g. Company and/orPlant
            /// </summary>
            public virtual string MasterSystemHierarchy { get;set; }
     
            /// <summary>
            /// Master systems unique  identification within the hierarchy.
            /// </summary>
            public virtual string MasterSystemId { get;set; }
     
            // association properties
            // association: Components
            private IList<MaterialComponent> materialComponents = new List<MaterialComponent>();
            public virtual IList<MaterialComponent> MaterialComponents {
                get { return this.materialComponents;}
            }
     
            // association: transactions
            private IList<Transaction> transactions = new List<Transaction>();
            public virtual IList<Transaction> Transactions {
                get { return this.transactions;}
            }
     
            // association: Messages
            private IList<MessageEvent> messageEvents = new List<MessageEvent>();
            public virtual IList<MessageEvent> MessageEvents {
                get { return this.messageEvents;}
            }
     
            // association: calendar events
            private IList<CalendarEvent> calendarEvents = new List<CalendarEvent>();
            public virtual IList<CalendarEvent> CalendarEvents {
                get { return this.calendarEvents;}
            }
     
            // association: alternatives
            private IList<OperationAlternative> operationAlternatives = new List<OperationAlternative>();
            public virtual IList<OperationAlternative> OperationAlternatives {
                get { return this.operationAlternatives;}
            }
     
            // association: allowedWorkplaces
            private IList<AllowedWorkplace> allowedWorkplaces = new List<AllowedWorkplace>();
            public virtual IList<AllowedWorkplace> AllowedWorkplaces {
                get { return this.allowedWorkplaces;}
            }
     
            // association: operating resource
            public virtual Item OperatingResource {
                get;
                set;
            }
     
            // association: cycle time unit
            public virtual UnitOfMeasure CycleUoM {
                get;
                set;
            }
     
            // association: Workplace
            public virtual Workplace Workplace {
                get;
                set;
            }
     
            // association: work order
            public virtual WorkOrder WorkOrder {
                get;
                set;
            }
     
        }
    }

    This is the metadatasource part:

    public void PrepareOperationAssociationConfigurations(MappingConfiguration<Operation> configuration) {
        configuration.HasAssociation(x => x.MaterialComponents).WithOpposite(x => x.Operation).HasConstraint((m, d)=>d.OperationId == m.Id).IsManaged().IsDependent();
        configuration.HasAssociation(x => x.Transactions).WithOpposite(x => x.Operation).HasConstraint((m, d)=>d.OperationId == m.Id).IsManaged().IsDependent();
        configuration.HasAssociation(x => x.MessageEvents).WithOpposite(x => x.Operation).HasConstraint((m, d)=>d.OperationId == m.Id).IsManaged().IsDependent();
        configuration.HasAssociation(x => x.CalendarEvents).WithOpposite(x => x.Operation).HasConstraint((m, d)=>d.OperationId == m.Id).IsManaged().IsDependent();
        configuration.HasAssociation(x => x.OperationAlternatives).HasConstraint((d, m)=>d.WorkOrderId == m.WorkOrderId && d.SequenceNumber==m.SequenceNumber);
        configuration.HasAssociation(x => x.AllowedWorkplaces).HasConstraint((d, m)=>d.WorkOrderId == m.WorkOrderId && d.SequenceNumber==m.SequenceNumber);
        configuration.HasAssociation(x => x.OperatingResource).WithOpposite(x => x.OperationsAsOpRes).HasConstraint((d, m)=>d.OperatingResourceId == m.Id);
        configuration.HasAssociation(x => x.CycleUoM).WithOpposite(x => x.Operations).HasConstraint((d, m)=>d.CycleTimeUoM  == m.Id).IsManaged();
        configuration.HasAssociation(x => x.Workplace).WithOpposite(x => x.Operations).HasConstraint((d, m)=>d.WorkplaceId == m.Id);
        configuration.HasAssociation(x => x.WorkOrder).WithOpposite(x => x.Operations).HasConstraint((d, m)=>d.WorkOrderId == m.Id).IsManaged();
    }

     

    Starting the application I getthis error message:

    The field 'Operation_operationAlternatives' of class 'idee5.Dispatcher.Model.DAL.OperationAlternative' references a primary key field '<WorkOrderId>k__BackingField' of class 'idee5.Dispatcher.Model.DAL.Operation' that could not be found. --> DispatcherEntities/namespace[idee5.Dispatcher.Model.DAL]/class[Operation]/field[operationAlternatives]/collection/inverse="{auto}"/db-ref="<WorkOrderId>k__BackingField"

    Any ideas what I did wrong?

    Kind regards

    Bernd

  2. Bernd
    Bernd avatar
    91 posts
    Member since:
    Feb 2013

    Posted 16 Dec 2016 in reply to Bernd Link to this post

    HasConstraint seems to need a primary key. So I rephrase my question:

    How can I tell Data Access that there is a connection betweeen OperationAlternative and Operation through WorkOrderId and SequenceNumber? Which are not the primary key of Operation.

Back to Top