Click here to Skip to main content
14,331,020 members
Rate this:
Please Sign up or sign in to vote.
See more:
hi i have two class

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
using Cor;

namespace IVF_EHR.Models
{
    public class FileExtrainformation
    {
        public FileExtrainformation()
        {
            FileExtrainformationID = Guid.NewGuid();
        }
        [Key]
        public Guid FileExtrainformationID { get; set; }
        public long? FileID { get; set; }
        
        public long? EconomicID { get; set; }
        [ForeignKey("EconomicID")]
        public virtual BaseinformationExtraFileInformation Economic { get; set; }
        [MaxLength(100)]
        public string ExtraFileInfomrationComment { get; set; }
        public bool? ExtraInfomationSiadat { get; set; }
        public long? RaceEthnicityPID { get; set; }
        [ForeignKey("RaceEthnicityPID")]
        public virtual BaseinformationExtraFileInformation RaceEthnicityP { get; set; }
        public long? ExtrainformationABOFemaleID { get; set; }
        [ForeignKey("ExtrainformationABOFemaleID")]
        public virtual BaseInformationFemaleHistory ExtrainformationABOFemale { get; set; }
        public long? FemaleSkinColorID { get; set; }
        [ForeignKey("FemaleSkinColorID")]
        public virtual BaseinformationExtraFileInformation FemaleSkinColor { get; set; }
        public long? FemaleEyelColorID { get; set; }
        [ForeignKey("FemaleEyelColorID")]
        public virtual BaseinformationExtraFileInformation FemaleEyelColor { get; set; }
        public long? FemaleHairID { get; set; }
        [ForeignKey("FemaleHairID")]
        public virtual BaseinformationExtraFileInformation FemaleHair { get; set; }
        public long? FemaleBodyID { get; set; }
        [ForeignKey("FemaleBodyID")]
        public virtual BaseinformationExtraFileInformation FemaleBody { get; set; }
        public long? FemaleAdherenceID { get; set; }
        [ForeignKey("FemaleAdherenceID")]
        public virtual BaseinformationExtraFileInformation FemaleAdherence { get; set; }
        public bool? FemaleSurrogate { get; set; }
        public bool? FemaleDonner { get; set; }
        public bool? ExtraInfomationSiadatMale { get; set; }
        public long? RaceEthnicityWID { get; set; }
        [ForeignKey("RaceEthnicityWID")]
        public virtual BaseinformationExtraFileInformation RaceEthnicityW { get; set; }
        public long? ExtrainformationABOMaleID { get; set; }
        [ForeignKey("ExtrainformationABOMaleID")]
        public virtual BaseInformationMaleHistory ExtrainformationABOMale { get; set; }
        public long? MaleSkinColorID { get; set; }
        [ForeignKey("MaleSkinColorID")]
        public virtual BaseinformationExtraFileInformation MaleSkinColor { get; set; }
        public long? MaleEyelColorID { get; set; }
        [ForeignKey("MaleEyelColorID")]
        public virtual BaseinformationExtraFileInformation MaleEyelColor { get; set; }
        public long? MaleHairID { get; set; }
        [ForeignKey("MaleHairID")]
        public virtual BaseinformationExtraFileInformation MaleHair { get; set; }
        public long? MaleBodyID { get; set; }
        [ForeignKey("MaleBodyID")]
        public virtual BaseinformationExtraFileInformation MaleBody { get; set; }
        public long? MaleAdherenceID { get; set; }
        [ForeignKey("MaleAdherenceID")]
        public virtual BaseinformationExtraFileInformation MaleAdherence { get; set; }
        public bool? MaleDonner { get; set; }
        [NotMapped]
        public bool? IsLoaded { get; set; }
        VitalSign LS = null;
        IVFContext IVFDB = null;
        [NotMapped]
        public float? ExtraInformationLength
        {
            get
            {
                string FileIDStr = this.FileID.ToStringNull();
                float? result = 0;
                if (IVFDB == null)
                    IVFDB = new IVFContext();

                if (LS == null)
                    LS = (from item in IVFDB.VitalSigns
                          where item.VitalSex == 1 && item.VitalSignsDate != null && item.FileID == FileIDStr
                          orderby item.VitalSignsDate descending 
                          select item).FirstOrDefault();

                if (LS != null)
                    result = LS.VitalSignsLength;
                return result;
            }
        }

        [NotMapped]
        public float? ExtraInformationWeight
        {
            get
            {
                string FileIDStr = this.FileID.ToStringNull();
                float? result = 0;
                if (IVFDB == null)
                    IVFDB = new IVFContext();

                if (LS == null)
                    LS = (from item in IVFDB.VitalSigns
                          where item.VitalSex == 1 && item.VitalSignsDate != null && item.FileID == FileIDStr
                          orderby item.VitalSignsDate descending
                          select item).FirstOrDefault();

                if (LS != null)
                    result = LS.VitalSignsWeight;
                return result;
            }
        }

        VitalSign LSM = null;
        [NotMapped]
        public float? ExtraInformationLengthW
        {
            get
            {
                string FileIDStr = this.FileID.ToStringNull();
                float? result = 0;
                if (IVFDB == null)
                    IVFDB = new IVFContext();

                if (LSM == null)
                    LSM = (from item in IVFDB.VitalSigns
                           where item.VitalSex == 0 && item.VitalSignsDate != null && item.FileID == FileIDStr
                          orderby item.VitalSignsDate descending
                          select item).FirstOrDefault();

                if (LSM != null)
                    result = LSM.VitalSignsLength;
                return result;
            }
        }

        [NotMapped]
        public float? ExtraInformationWeightW
        {
            get
            {
                string FileIDStr = this.FileID.ToStringNull();
                float? result = 0;
                if (IVFDB == null)
                    IVFDB = new IVFContext();

                if (LSM == null)
                    LSM = (from item in IVFDB.VitalSigns
                           where item.VitalSex == 0 && item.VitalSignsDate != null && item.FileID == FileIDStr
                           orderby item.VitalSignsDate descending
                           select item).FirstOrDefault();

                if (LSM != null)
                    result = LSM.VitalSignsWeight;
                return result;
            }
        }
    }
}


and


using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
using System.Data.Entity;
using Cor;

namespace IVF_EHR.Models
{
    public class FemaleHistory
    {
        [Key]
        public Guid FemaleHistoryID { get; set; }
        public long? FileID { get; set; }
        [MaxLength(10)]
        public string FertilityEvaluationsresult4N { get; set; }
        [MaxLength(10)]
        public string FertilityEvaluationsresult3N { get; set; }

        [MaxLength(50)]
        public string VitD { get; set; }
        public decimal? VitDValue { get; set; }

        public long? FertilityEvaluationsresult8Combobox { get; set; }
        [ForeignKey("FertilityEvaluationsresult8Combobox")]
        public virtual BaseInformationFemaleHistory FertilityEvaluationsresult8ComboboxO { get; set; }

        public long? FertilityEvaluationsresult10ComboBox { get; set; }
        [ForeignKey("FertilityEvaluationsresult10ComboBox")]
        public virtual BaseInformationFemaleHistory FertilityEvaluationsresult10ComboBoxO { get; set; }

        public long? FertilityEvaluationsresult14Combo { get; set; }
        [ForeignKey("FertilityEvaluationsresult14Combo")]
        public virtual BaseInformationFemaleHistory FertilityEvaluationsresult14ComboO { get; set; }

        //Menstrual Cycle
        public int? AgeStarted { get; set; }
        [MaxLength(20)]
        public string LMP { get; set; }
        [MaxLength(20)]
        public string PreviousLMP { get; set; }
        public int? MinRangeDurD { get; set; }
        public int? MaxRangeDurD { get; set; }
        public int? MinBleedDurD { get; set; }
        public int? MaxBleedDurD { get; set; }
        public bool? CyclicMood { get; set; }
        MEHRMISContext MehrDB = new MEHRMISContext();
        [NotMapped]
        public File FoundFile = null;
        [NotMapped]
        public bool? SecoundMarriage 
        {
            get
            {
                if (FoundFile == null)
                    FoundFile = (from item in MehrDB.Files where item.FileID == this.FileID select item).FirstOrDefault();

                if (FoundFile != null)
                    return FoundFile.SecoundMarriage;
                else
                    return null;
            }
        }
        public int? Duration
        {
            get
            {
                if (FoundFile == null)
                    FoundFile = (from item in MehrDB.Files where item.FileID == this.FileID select item).FirstOrDefault();

                if (FoundFile != null)
                    return FoundFile.Duration;
                else
                    return null;
            }
        }
        public long? PainfulID { get; set; }
        [ForeignKey("PainfulID")]
        public virtual BaseInformationFemaleHistory BaseInformationFemaleHistory { get; set; }
        public long? PainBtwPeriodsID { get; set; }
        [ForeignKey("PainBtwPeriodsID")]
        public virtual BaseInformationFemaleHistory PainBtwPeriods { get; set; }
        public long? InterruptedExctPregID { get; set; }
        [ForeignKey("InterruptedExctPregID")]
        public virtual BaseInformationFemaleHistory InterruptedExctPreg { get; set; }
        public long? BleedBtwPeriodsID { get; set; }
        [ForeignKey("BleedBtwPeriodsID")]
        public virtual BaseInformationFemaleHistory BleedBtwPeriods { get; set; }
        public long? NippleDischargeID { get; set; }
        [ForeignKey("NippleDischargeID")]
        public virtual BaseInformationFemaleHistory NippleDischarge { get; set; }
        public long? BloatingBeforeID { get; set; }
        [ForeignKey("BloatingBeforeID")]
        public virtual BaseInformationFemaleHistory BloatingBefore { get; set; }
        public long? BreastTendernessID { get; set; }
        [ForeignKey("BreastTendernessID")]
        public virtual BaseInformationFemaleHistory BreastTenderness { get; set; }
        public long? BleedingID { get; set; }
        [ForeignKey("BleedingID")]
        public virtual BaseInformationFemaleHistory Bleeding { get; set; }
        [MaxLength(100)]
        public string MenstrualCycleComment { get; set; }

        //Contraception
        public int? DurationMonths { get; set; }
        public int? DurationMonths2 { get; set; }
        public int? YearsWO { get; set; }
        public bool? SurgSteril { get; set; }
        public long? MethodID { get; set; }
        [ForeignKey("MethodID")]
        public virtual BaseInformationFemaleHistory Method { get; set; }
        public long? MethodID2 { get; set; }
        [ForeignKey("MethodID2")]
        public virtual BaseInformationFemaleHistory Method2 { get; set; }

        VitalSign LoadLastVS = null;
        
        private void LoadLastVSOBj()
        {
            if (IVFDB == null)
                IVFDB = new IVFContext();
            string FileID = this.FileID.ToStringNull();
            if (LoadLastVS == null)
            {
                LoadLastVS = (from item in IVFDB.VitalSigns
                              where item.FileID == FileID && item.VitalSex == 1
                              orderby item.VitalSignsDate descending
                              select item).FirstOrDefault();
            }
            

        }
        //BMI
        float? height = 0;
        [NotMapped]
        public float? Height 
        {
            get
            {
                LoadLastVSOBj();
                if (LoadLastVS != null)
                {
                    height = LoadLastVS.VitalSignsLength;
                }

                return height;
            }
            set
            {

            } 
        }
        float? weight = 0;
        [NotMapped]
        public float? Weight 
        { 
            get
            {
                LoadLastVSOBj();
                if (LoadLastVS != null)
                    weight = LoadLastVS.VitalSignsWeight;

                return weight;
            }
            set
            {

            } 
        }
        [NotMapped]
        public float? KGM2 
        {
            get
            {
                float? h = this.Height;
                float? w = this.Weight;
                if (w == 0)
                    return 0;

                return w / (h * h);
            }
            set
            {

            } 
        }

        //Sexual
        public int? FrequencyWK { get; set; }
        public bool? Dyspareunia { get; set; }
        [MaxLength(600)]
        public string UnknownStuffText { get; set; }
        public long? LubricationID { get; set; }
        [ForeignKey("LubricationID")]
        public virtual BaseInformationFemaleHistory Lubrication { get; set; }
        public long? VagDischargeID { get; set; }
        [ForeignKey("VagDischargeID")]
        public virtual BaseInformationFemaleHistory VagDischarge { get; set; }
        public long? SexualProblemsID { get; set; }
        [ForeignKey("SexualProblemsID")]
        public virtual BaseInformationFemaleHistory SexualProblems { get; set; }
        public long? BleedIntercourseID { get; set; }
        [ForeignKey("BleedIntercourseID")]
        public virtual BaseInformationFemaleHistory BleedIntercourse { get; set; }

        //Risks
        public int? SmokingNbrWeek { get; set; }
        public int? SmokingYears { get; set; }
        public bool? DES { get; set; }
        [MaxLength(20)]
        public string SmokingStopDate { get; set; }
        public int? CoffeeCupsDay { get; set; }
        public int? EIOHGlassWeek { get; set; }
        [MaxLength(20)]
        public string StartDateRisk { get; set; }
        [MaxLength(20)]
        public string BloodTransDate { get; set; }
        public int? DrugYears { get; set; }
        [MaxLength(600)]
        public string CommentsRisks { get; set; }
        public long? IndustrialChemID { get; set; }
        [ForeignKey("IndustrialChemID")]
        public virtual BaseInformationFemaleHistory IndustrialChem { get; set; }
        public long? CMVID { get; set; }
        [ForeignKey("CMVID")]
        public virtual BaseInformationFemaleHistory CMV { get; set; }
        public long? ToxoID { get; set; }
        [ForeignKey("ToxoID")]
        public virtual BaseInformationFemaleHistory Toxo { get; set; }
        public long? BloodTransfusionID { get; set; }
        [ForeignKey("BloodTransfusionID")]
        public virtual BaseInformationFemaleHistory BloodTransfusion { get; set; }
        public long? RadiationID { get; set; }
        [ForeignKey("RadiationID")]
        public virtual BaseInformationFemaleHistory Radiation { get; set; }
        public long? NonRxDrugID { get; set; }
        [ForeignKey("NonRxDrugID")]
        public virtual BaseInformationFemaleHistory NonRxDrug { get; set; }
        public long? SmokingTypeID { get; set; }
        [ForeignKey("SmokingTypeID")]
        public virtual BaseInformationFemaleHistory SmokingType { get; set; }

        //Health
        public bool? Rubbia { get; set; }
        public bool? Varicela { get; set; }
        public long? HealthCurrentID { get; set; }
        [ForeignKey("HealthCurrentID")]
        public virtual BaseInformationFemaleHistory HealthCurrent { get; set; }
        public long? ABOID { get; set; }
        [ForeignKey("ABOID")]
        public virtual BaseInformationFemaleHistory ABO { get; set; }

        //Psychosocial
        [MaxLength(20)]
        public string TherapyDate { get; set; }
        public int? PsychosocialDurationMonths { get; set; }
        public bool? Family { get; set; }
        public bool? IntinateRelations { get; set; }
        public bool? SelfEsteem { get; set; }
        public bool? BodyImage { get; set; }
        public long? AnxiousID { get; set; }
        [ForeignKey("AnxiousID")]
        public virtual BaseInformationFemaleHistory Anxious { get; set; }
        public long? DepressedID { get; set; }
        [ForeignKey("DepressedID")]
        public virtual BaseInformationFemaleHistory Depressed { get; set; }
        public long? SupportAvaliableID { get; set; }
        [ForeignKey("SupportAvaliableID")]
        public virtual BaseInformationFemaleHistory SupportAvaliable { get; set; }

        //Genetic
        public long? SickleCellTestedID { get; set; }
        [ForeignKey("SickleCellTestedID")]
        public virtual BaseInformationFemaleHistory SickleCellTested { get; set; }
        public long? HgbElectrophPlusID { get; set; }
        [ForeignKey("HgbElectrophPlusID")]
        public virtual BaseInformationFemaleHistory HgbElectrophPlus { get; set; }
        public long? Gluc6PhosDefID { get; set; }
        [ForeignKey("Gluc6PhosDefID")]
        public virtual BaseInformationFemaleHistory Gluc6PhosDef { get; set; }
        public long? CysticFibroeisQID { get; set; }
        [ForeignKey("CysticFibroeisQID")]
        public virtual BaseInformationFemaleHistory CysticFibroeisQ { get; set; }
        public long? ScreenThalassemiaQID { get; set; }
        [ForeignKey("ScreenThalassemiaQID")]
        public virtual BaseInformationFemaleHistory ScreenThalassemiaQ { get; set; }
        public long? KaryotypeGeneticID { get; set; }
        [ForeignKey("KaryotypeGeneticID")]
        public virtual BaseInformationFemaleHistory KaryotypeGenetic { get; set; }
        [MaxLength(50)]
        public string CysticFibroeisQIDText { get; set; }
        [MaxLength(50)]
        public string Gluc6PhosDefIDText { get; set; }

        //Endocrine
        public long? Short1ID { get; set; }
        [ForeignKey("Short1ID")]
        public virtual BaseInformationFemaleHistory Short1 { get; set; }
        public int? WeeklyHirs { get; set; }
        public int? EndocrineAge1 { get; set; }
        public long? Short2ID { get; set; }
        [ForeignKey("Short2ID")]
        public virtual BaseInformationFemaleHistory Short2 { get; set; }
        public int? WeeklyHirs2 { get; set; }
        public int? EndocrineAge2 { get; set; }
        [MaxLength(500)]
        public string EndocrineComments { get; set; }

        //Fertility Evaluations
        [MaxLength(20)]
        public string FertilityEvaluationsLH { get; set; }
        [MaxLength(20)]
        public string Testosterone { get; set; }
        [MaxLength(20)]
        public string Thyroid { get; set; }
        public double? FertilityEvaluationsresult1 { get; set; }
        public double? FertilityEvaluationsresult2 { get; set; }
        [MaxLength(20)]
        public string FertilityEvaluationsBBT { get; set; }
        [MaxLength(20)]
        public string FertilityEvaluationsPRL { get; set; }
        [MaxLength(20)]
        public string FertilityEvaluationsP4 { get; set; }
        [MaxLength(20)]
        public string FertilityEvaluationsHSG { get; set; }
        public double? FertilityEvaluationsresult5 { get; set; }
        public double? FertilityEvaluationsresult6 { get; set; }
        [MaxLength(20)]
        public string FertilityEvaluationsPCT { get; set; }
        [MaxLength(20)]
        public string FertilityEvaluationsE2 { get; set; }
        [MaxLength(20)]
        public string FertilityEvaluationsASA { get; set; }
        [MaxLength(20)]
        public string FertilityEvaluationsUltraSound { get; set; }
        public double? FertilityEvaluationsresult9 { get; set; }
        [MaxLength(20)]
        public string FertilityEvaluationsFSH { get; set; }
        [MaxLength(20)]
        public string FertilityEvaluationsDHEAS { get; set; }
        [MaxLength(20)]
        public string FertilityEvaluationsMycoplasma { get; set; }
        [MaxLength(20)]
        public string FertilityEvaluationsAMH { get; set; }
        public double? FertilityEvaluationsresult12 { get; set; }
        public double? FertilityEvaluationsresult13 { get; set; }
        public double? FertilityEvaluationsresult15 { get; set; }

        //Fertility Therapies 
        [MaxLength(20)]
        public string EndometrialBiopsy { get; set; }
        [MaxLength(20)]
        public string Laparoscopy { get; set; }
        [MaxLength(20)]
        public string Hysteroscopy { get; set; }
        public bool? Adhesiolysis { get; set; }
        public bool? CervicalCautery { get; set; }
        public bool? TubalReversalDone { get; set; }
        [MaxLength(20)]
        public string TubalReversalDate { get; set; }

        public int? Gravidity { get; set; }
        public int? Biochem { get; set; }
        public int? TOPBMSummery { get; set; }
        public int? MultiPregDotGravid { get; set; }
        public int? EABOBSummary { get; set; }
        public int? EctopicPreg { get; set; }
        public int? FullTerm { get; set; }
        public int? SAB { get; set; }
        public int? InfertilityMon { get; set; }
        public int? PreTerm { get; set; }
        public int? TotalPregnancies { get; set; }
        public string FertilityEvaluationsCA125 { get; set; }
        public double? FertilityEvaluationsresultCA125 { get; set; }

        public virtual List<BaseInformationFemaleHistoryCBL> FemaleFathers { get; set; }
        public virtual List<BaseInformationFemaleHistoryCBL> FemaleMothers { get; set; }
        public virtual List<BaseInformationFemaleHistoryCBL> FemaleBrothers { get; set; }
        public virtual List<BaseInformationFemaleHistoryCBL> FemaleSisters { get; set; }
        public virtual List<BaseInformationFemaleHistoryCBL> FemaleRiskss { get; set; }

        public virtual List<PastSurgeries> PastSurgeriess { get; set; }

        

        [NotMapped]
        public bool IsLoaded { get; set; }

        
    }
}


i need when this property ExtrainformationABOFemaleID from fileExtrainformation class changed automatically ABOID from FemaleHistory changed.
i mean this tow property always sould be equal with each other.
sory my english is not good
Posted
Comments
Nathan Minier 12-Aug-14 9:02am
   
That's painful to look at. You should consider breaking your code into different POCOs, perhaps ones suggested by your comments.
Rate this:
Please Sign up or sign in to vote.

Solution 1

Your POCO is setup wrong for a proper FK relationship. You'll need to reformat some of it like so:

public long? ExtrainformationABOFemaleID { get; set; }
[ForeignKey("ExtrainformationABOFemaleID")]


should be

[ForeignKey("ExtraInformationFemale")]
public long? ExtrainformationABOFemaleID { get; set; }

public virtual FemaleHistory ExtraInformationFemale { get; set; }


The virtual property will provide the relation.
   
Comments
meysam_25 12-Aug-14 11:38am
   
its not what i am looking for
the relation are set but i need another relation that automatically update this property ABOID and ExtrainformationABOFemaleID
Rate this:
Please Sign up or sign in to vote.

Solution 2

no one never helped me .
i am my own .
ok i will figure out.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100