#!/bin/bash if [ -z "$1" ] || [ -z "$2" ]; then echo "No name supplied!" exit fi project_name="$1" feature_name="$2" features=("${@:3}") if [ -z features ]; then features=("string Name") fi #=== Add to Data layer dir="../$project_name/Data" # Create the Feature.cs DB model class cat > $dir/$feature_name.cs<< FILE using System; namespace $project_name.Data.Models { public class $feature_name { $( for feature in "${features[@]}"; do echo -e "\r\t\tpublic $feature { get; set; }" done ) } } FILE # Add the DbSet of the Feature to DbContext dbset="public DbSet<$feature_name> ${feature_name}s { get; set; }" dbcontext_path="$dir/${project_name}Context.cs" if grep -Fq "DbSet" $dbcontext_path; then sed -z -i "s/.*DbSet[^\n]*\n/&\t\t$dbset\n/" $dbcontext_path else sed -i "11 i \\\t\t$dbset\n" $dbcontext_path fi