public void Create(Animal animal) { var connectionString = RuntimeConfiguration.GetConnectionString("AnimalContext"); using var adapter = new DataAccessAdapter(connectionString); if (animal.GetType().IsSubclassOf(typeof(Animal))) { switch (animal) { case Dog: adapter.SaveEntity(new DogEntity { Name = animal.Name, Type = (int)animal.Type }); break; case Cow: adapter.SaveEntity(new CowEntity { Name = animal.Name, Type = (int)animal.Type }); break; } } else { adapter.SaveEntity(new AnimalEntity { Name = animal.Name, Type = (int)animal.Type }); } }
public void Create(WeatherForecast model) { var connectionString = RuntimeConfiguration.GetConnectionString("WeatherContext"); using var adapter = new DataAccessAdapter(connectionString); var metaData = new LinqMetaData(adapter); }
/// <summary>Reads the value of the setting with the key ConnectionStringKeyName from the *.config file and stores that value as the active connection string to use for this object.</summary> /// <returns>connection string read</returns> private static string ReadConnectionStringFromConfig() { #if NETSTANDARD2_0 return(RuntimeConfiguration.GetConnectionString(ConnectionStringKeyName)); #else return(ConfigFileHelper.ReadConnectionStringFromConfig(ConnectionStringKeyName)); #endif }
public void Delete(int id) { var connectionString = RuntimeConfiguration.GetConnectionString("AnimalContext"); using var adapter = new DataAccessAdapter(connectionString); adapter.DeleteEntity(new AnimalEntity { Id = id }); }
public void Create(Cow cow) { var connectionString = RuntimeConfiguration.GetConnectionString("AnimalContext"); using var adapter = new DataAccessAdapter(connectionString); adapter.SaveEntity(new CowEntity { Name = cow.Name, Type = (int)cow.Type }); }
/// <summary>Gets the connection string.</summary> /// <returns>the connection string as set by code or in the config file.</returns> protected override string GetConnectionString() { if (String.IsNullOrEmpty(ActualConnectionString)) { #if NETSTANDARD || NETCOREAPP ActualConnectionString = RuntimeConfiguration.GetConnectionString(connectionKeyString); #else ActualConnectionString = ConfigFileHelper.ReadConnectionStringFromConfig(connectionKeyString); #endif } return(ActualConnectionString); }
public void Update(int id, TodoItem item) { var connectionString = RuntimeConfiguration.GetConnectionString("TodoContext"); using var adapter = new DataAccessAdapter(connectionString); var entity = new TodoItemEntity { Id = id }; adapter.FetchEntity(entity); entity.Title = item.Title; adapter.SaveEntity(entity); }
public IList <TodoItem> GetAll() { var connectionString = RuntimeConfiguration.GetConnectionString("TodoContext"); using var adapter = new DataAccessAdapter(connectionString); var metaData = new LinqMetaData(adapter); return(metaData.TodoItem.Select(item => new TodoItem { Id = item.Id, Title = item.Title }).ToList()); }
public WeatherForecast[] GetForecast() { var connectionString = RuntimeConfiguration.GetConnectionString("WeatherContext"); using var adapter = new DataAccessAdapter(connectionString); var metaData = new LinqMetaData(adapter); return(metaData.WeatherForecast.Select(forecast => new WeatherForecast { Date = forecast.Date ?? DateTime.Today, Summary = forecast.Summary, TemperatureC = forecast.TemperatureC ?? 0 }).ToArray()); }
public void Update(int id, Animal animal) { var connectionString = RuntimeConfiguration.GetConnectionString("AnimalContext"); using var adapter = new DataAccessAdapter(connectionString); var entity = new AnimalEntity { Id = id }; adapter.FetchEntity(entity); entity.Type = (int)animal.Type; entity.Name = animal.Name; adapter.SaveEntity(entity); }
public TodoItem GetById(int id) { var connectionString = RuntimeConfiguration.GetConnectionString("TodoContext"); using var adapter = new DataAccessAdapter(connectionString); var metaData = new LinqMetaData(adapter); return(metaData.TodoItem.Where(item => item.Id == id) .Select(item => new TodoItem { Id = item.Id, Title = item.Title }).SingleOrDefault()); }
public IList <Animal> GetAll() { var connectionString = RuntimeConfiguration.GetConnectionString("AnimalContext"); using var adapter = new DataAccessAdapter(connectionString); var metaData = new LinqMetaData(adapter); return(metaData.Animal .Select(animal => new Animal { Id = animal.Id, Type = (AnimalType)animal.Type, Name = animal.Name }).ToList()); }
public Animal GetById(int id) { var connectionString = RuntimeConfiguration.GetConnectionString("AnimalContext"); using var adapter = new DataAccessAdapter(connectionString); var metaData = new LinqMetaData(adapter); return(metaData.Animal .Where(animal => animal.Id == id) .Select(animal => new Animal { Id = animal.Id, Type = (AnimalType)animal.Type, Name = animal.Name }).SingleOrDefault()); }
/// <summary>Reads the value of the setting with the key ConnectionStringKeyName from the *.config file and stores that value as the active connection string to use for this object.</summary> /// <returns>connection string read</returns> private static string ReadConnectionStringFromConfig() { return(RuntimeConfiguration.GetConnectionString(ConnectionStringKeyName)); //return ConfigFileHelper.ReadConnectionStringFromConfig(ConnectionStringKeyName); }