//DEMOSTOP#2 private static void CreateDatabase(DataContextBase todo) { try { // Generate the database (with structure) from the code-based data context todo.CreateDatabase(); // Populate the database with system data GenerateSystemData(todo); // Create a default "Hello 'ToDo' note" -- OPTIONAL Task items = new Task(); items.Id = Guid.NewGuid(); items.Title = "Welcome to the \"Todo\"!"; items.LocationID = new Guid(Utils.LocationIDDefault); items.Completed = true; todo.Items.InsertOnSubmit(items); todo.SubmitChanges(); } catch (Exception ex) { MessageBox.Show("Error while creating the DB: " + ex.Message); System.Diagnostics.Debug.WriteLine("Error while creating the DB: " + ex.Message); } }
public static void InitializeDatabase(DataContextBase todo) { using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication()) { if (iso.FileExists("ToDo.sdf")) return; CreateDatabase(todo); } }
public GlobalConfig Get(int i) { DataContextBase <GlobalConfig> dataContext = new DataContextBase <GlobalConfig>("GlobalConfigs"); return(dataContext.GetDocumentByIndex(i)); }
public IEnumerable <GlobalConfig> Get() { DataContextBase <GlobalConfig> dataContext = new DataContextBase <GlobalConfig>("GlobalConfigs"); return(dataContext.GetDocuments()); }
private static void GenerateSystemData(DataContextBase todo) { //Add projects Project project = new Project(); project.Id = new Guid(Utils.ProjectIDDefault); project.Name = LocalizedStrings.DefaultProjectName; project.Description = LocalizedStrings.DefaultProjectDescription; project.Color = Colors.Gray.ToString(); todo.Projects.InsertOnSubmit(project); List<Location> locations = new List<Location>(); Location location = new Location (); location = new Location(); location.Id = new Guid(Utils.LocationIDDefault); location.Name = LocalizedStrings.DefaultLocationName; location.Description = LocalizedStrings.DefaultLocationDescription; location.Latitude = 0; location.Longitude = 0; locations.Add(location); location = new Location(); location.Id = Guid.NewGuid(); location.Name = "Work"; location.Address = "One Microsoft Way"; location.Description = location.Address; location.City = "Redmond"; location.State = "WA"; location.Latitude = 47.639767; location.Longitude = -122.129755; location.ZipCode = "98052"; locations.Add(location); location = new Location(); location.Id = Guid.NewGuid(); location.Name = "Home"; location.Address = "123 Main"; location.Description = "123 Main Seattle, WA"; location.City = "Seattle"; location.State = "WA"; location.Latitude = 47.599903; location.Longitude = -122.333728; location.ZipCode = "98104"; locations.Add(location); todo.Locations.InsertAllOnSubmit (locations); //Add attachment types List<AttachmentType> attachmentTypes = new List<AttachmentType>(); AttachmentType attachmentType = new AttachmentType(); attachmentType.Id = new Guid(Utils.AttachmentTypeIDText); attachmentType.Name = "Text"; attachmentTypes.Add(attachmentType); attachmentType = new AttachmentType(); attachmentType.Id = new Guid(Utils.AttachmentTypeIDImage); attachmentType.Name = "Image"; attachmentTypes.Add(attachmentType); attachmentType = new AttachmentType(); attachmentType.Id = new Guid(Utils.AttachmentTypeIDVoice); attachmentType.Name = "Voice"; attachmentTypes.Add(attachmentType); todo.AttachmentType.InsertAllOnSubmit(attachmentTypes); //Submit try { todo.SubmitChanges(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
public ImportResultHandler(DataContextBase <ImportResultDbo> dataContext) { this.dataContext = dataContext; }
public static T FindSingle <T>(this DataContextBase context, Expression <Func <T, bool> > predicate) where T : EntityBase { return(context.FindSingle(new Specification <T>(predicate))); }
public MessageHandler(DataContextBase <MessageDbo> dataContext) { this.dataContext = dataContext; }
public override object[] GetContextConstructorArguments(IConnectionInfo r) { return(new object[] { DataContextBase.GetConnection(r.DatabaseInfo.GetCxString(), r.DatabaseInfo.Provider) }); }
protected override Expression VisitMethodCall(MethodCallExpression m) { if (m.Method.DeclaringType == typeof(DataFacade)) { if (m.Method.IsGenericMethod && m.Method.GetGenericMethodDefinition() == _dataFacadeGetDataMethodInfo) { object result = m.Method.Invoke(null, null); return(Expression.Constant(result is IDataFacadeQueryable ? HandleMultipleSourceQueryable(result) : result)); } // Handling some of the overloads of GetData() if (m.Method.Name == _dataFacadeGetDataMethodInfo.Name && m.Arguments.All(arg => (arg as ConstantExpression) != null)) { object[] parameters = m.Arguments.Select(arg => (arg as ConstantExpression).Value).ToArray(); object result = m.Method.Invoke(null, parameters); return(Expression.Constant(result is IDataFacadeQueryable ? HandleMultipleSourceQueryable(result) : result)); } throw new NotSupportedException("Supporing for DataFacade method '{0}' or one of it's overloads not yet implemented".FormatWith(m.Method.Name)); } if (m.Method.DeclaringType == typeof(DataConnection)) { if (m.Method.IsGenericMethod && m.Method.GetGenericMethodDefinition() == _dataConnectionGetDataMethodInfo) { var dataConnection = EvaluateExpression <DataConnection>(m.Object); object result = m.Method.Invoke(dataConnection, null); return(Expression.Constant(result is IDataFacadeQueryable ? HandleMultipleSourceQueryable(result) : result)); } throw new NotSupportedException("Supporing for DataConnection method '{0}' or one of it's overloads not yet implemented".FormatWith(m.Method.Name)); } // Replacing Guid.NewGuid() call with "newid()" sql statement if (m.Method.IsStatic && m.Method.DeclaringType == typeof(Guid) && m.Method.Name == "NewGuid" && _queryable != null) { var dataContext = GetContext(_queryable) as DataContextBase; if (dataContext != null) { return(Expression.Call(Expression.Constant(dataContext), DataContextBase.GetNewIdMethodInfo())); } } // Processing queries that have multiple IQueryable sources // Processing queries like // // multipleSourceQueryable.METHOD() // multipleSourceQueryable.METHOD(predicate) // multipleSourceQueryable(.Where(predicate))*.METHOD() // multipleSourceQueryable(.Where(predicate))*.METHOD(predicate) // // Where the supported METHOD options are: "Where", "Any", "Count", "First" and "FirstOrDefault" IQueryable[] sources = null; List <Expression> predicates = null; if (m.Method.IsStatic && (m.Method.Name == "Where" || m.Method.Name == "Any" || m.Method.Name == "All" || m.Method.Name == "Count" || m.Method.Name == "First" || m.Method.Name == "FirstOrDefault" || m.Method.Name == "Single" || m.Method.Name == "SingleOrDefault") && (m.Arguments.Count == 1 || (m.Arguments.Count == 2 && m.Arguments[1] is UnaryExpression)) && ExtractMultipleSourceQueryable(m.Arguments[0], ref sources, ref predicates)) { Expression operationPredicate = m.Arguments.Count == 2 ? (m.Arguments[1] as UnaryExpression).Operand : null; if (m.Method.Name == "All") { _queryable = _queryable ?? new bool[0].AsQueryable(); return(Expression.Constant(All(sources, predicates, operationPredicate))); } if (operationPredicate != null) { predicates.Add(operationPredicate); } if (m.Method.Name == "Where") { IQueryable loadedSet = LoadToMemory(sources, predicates); _queryable = _queryable ?? loadedSet; return(Expression.Constant(loadedSet)); } _queryable = _queryable ?? new bool[0].AsQueryable(); if (m.Method.Name == "Any") { return(Expression.Constant(Any(sources, predicates))); } if (m.Method.Name == "Count") { return(Expression.Constant(Count(sources, predicates))); } if (m.Method.Name == "First") { return(Expression.Constant(First(sources, predicates))); } if (m.Method.Name == "FirstOrDefault") { return(Expression.Constant(FirstOrDefault(sources, predicates))); } if (m.Method.Name == "Single") { return(Expression.Constant(Single(sources, predicates))); } if (m.Method.Name == "SingleOrDefault") { return(Expression.Constant(SingleOrDefault(sources, predicates))); } throw new InvalidOperationException("This code should not be reachable. Current expression: " + m); } // Processing queries like // // multipleSourceQueryable(.Where(predicate))*.Take(N) if (m.Method.IsStatic && m.Method.Name == "Take" && (m.Arguments.Count == 2 && m.Arguments[1] is ConstantExpression && (m.Arguments[1] as ConstantExpression).Value is int) && ExtractMultipleSourceQueryable(m.Arguments[0], ref sources, ref predicates)) { int count = (int)(m.Arguments[1] as ConstantExpression).Value; var result = Take(sources, count, predicates); _queryable = _queryable ?? result; return(Expression.Constant(result)); } return(base.VisitMethodCall(m)); }
public KeyValueHandler(DataContextBase <KeyValue> dataContext) { this.dataContext = dataContext; }
public TSqlHandler Create <TSqlHandler, TSqlEntity>(DataContextBase <TSqlEntity> dataContext) where TSqlHandler : SqlHandlerBase <TSqlEntity> where TSqlEntity : class { return(kernel.Get <TSqlHandler>(new ConstructorArgument("dataContext", dataContext))); }
public EmailSenderService(IEmailConfiguration emailConfiguration, DataContextBase dataContext) { _emailConfiguration = emailConfiguration; _dataContext = dataContext; }
public TSqlHandler Create <TSqlHandler, TSqlEntity>(DataContextBase <TSqlEntity> dataContext) where TSqlEntity : class where TSqlHandler : SqlHandlerBase <TSqlEntity> { return((TSqlHandler)ActivatorUtilities.CreateInstance(serviceProvider, typeof(TSqlHandler), dataContext)); }
public static void Execute(this DataContextBase context, string sql, params object[] parameters) { context.Execute(new Command(sql, parameters)); }
public PlaylistsHandler(DataContextBase <PlaylistDbo> dataContext) { this.dataContext = dataContext; }
public TempSessionHandler(DataContextBase <TempSessionDbo> dataContext) { this.dataContext = dataContext; }