Example #1
0
        public static void FillUnitListsTable()
        {
            //Obtaining the data source
            MeasurementsDataContext dbEventLog = new MeasurementsDataContext();

            List <string> FavoritUnitStrings = new List <string> {
                "m/s", "Km/h", "ml", "l/h"
            };

            //Create compiled query
            var fnUnitIdFromName = CompiledQuery.Compile((MeasurementsDataContext dbEventLog1, string UnitName) =>
                                                         from u in dbEventLog.Units
                                                         where u.Name == UnitName
                                                         select u.Id);

            // Execute the query
            // Remove all unit lists from dbEventLog.UnitLists
            dbEventLog.UnitLists.DeleteAllOnSubmit(dbEventLog.UnitLists);

            dbEventLog.SubmitChanges();

            // Fill named derived units into dbEventLog.Units
            int UnitListId = UnitListBaseNumber;

            int UnitListElementIndex = 0;

            foreach (string unitStr in FavoritUnitStrings)
            {
                // IPhysicalUnit pu = PhysicalMeasure.PhysicalUnit.Parse(unitStr);
                // IPhysicalQuantity pq = pu.ConvertToSystemUnit();

                var q = fnUnitIdFromName(dbEventLog, unitStr);

                int UnitListElementUnitId = q.ElementAtOrDefault(0);
                Debug.Assert(UnitListElementUnitId != 0);

                if (UnitListElementUnitId != 0)
                {
                    UnitList_LINQ ul_element = new UnitList_LINQ()
                    {
                        Id = UnitListElementBaseNumber + UnitListElementIndex, UnitId = UnitListElementUnitId, ListId = UnitListId
                    };
                    //UnitList ul_element = new UnitList() { UnitId = UnitListElementUnitId, ListId = UnitListId };
                    dbEventLog.UnitLists.InsertOnSubmit(ul_element);
                }
                else
                {
                    InternalError_LINQ.ApplicationInternalErrorLog("Error when adding '" + unitStr + "' as favorite unit. Found no unit named '" + unitStr + "'");
                }

                UnitListElementIndex++;
            }

            dbEventLog.SubmitChanges();
        }
 private void detach_UnitLists(UnitList_LINQ entity)
 {
     this.SendPropertyChanging();
     entity.Unit = null;
 }
 private void attach_UnitLists(UnitList_LINQ entity)
 {
     this.SendPropertyChanging();
     entity.Unit = this;
 }
 partial void DeleteUnitList(UnitList_LINQ instance);
 partial void UpdateUnitList(UnitList_LINQ instance);
 partial void InsertUnitList(UnitList_LINQ instance);