From 20482140c124fd1d5caaffcc9b0dfe853b30dd6f Mon Sep 17 00:00:00 2001 From: Roy Date: Sat, 27 Jan 2018 17:18:10 +0200 Subject: Re-factored DAL Observables using EF Code First !!!!!! --- .../Templates/ObservablesContextCodeFile.cshtml | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Software/Visual_Studio/Tango.CodeGeneration/Templates/ObservablesContextCodeFile.cshtml (limited to 'Software/Visual_Studio/Tango.CodeGeneration/Templates/ObservablesContextCodeFile.cshtml') diff --git a/Software/Visual_Studio/Tango.CodeGeneration/Templates/ObservablesContextCodeFile.cshtml b/Software/Visual_Studio/Tango.CodeGeneration/Templates/ObservablesContextCodeFile.cshtml new file mode 100644 index 000000000..43330235c --- /dev/null +++ b/Software/Visual_Studio/Tango.CodeGeneration/Templates/ObservablesContextCodeFile.cshtml @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Data.Entity; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Settings; + +namespace Tango.DAL.Observables +{ + public class ObservablesContext : DbContext + { + /// + /// Initializes a new instance of the class. + /// + /// The server file path. + /// if set to true will try to connect to an .mdf file. + public ObservablesContext(String path, bool isFile) : base(ComposeConnectionString(path, isFile)) + { + + } + + /// + /// Composes the connection string. + /// + /// The source. + /// if set to true [is file]. + /// + private static String ComposeConnectionString(String source, bool isFile) + { + if (!isFile) + { + return String.Format("Data Source={0};Initial Catalog=Tango;Integrated Security=true", source); + } + else + { + return null; + } + } + + /// + /// Creates a default remote database context by the address specified in . + /// + /// + public static ObservablesContext CreateDefault() + { + return new ObservablesContext(SettingsManager.Default.DataBase.SQLServerAddress, false); + } + + @foreach (var prop in Model.Properties) + { +
+ /// + /// Gets or sets the @(prop.Name). + /// + public @(prop.Type) @(prop.Name) { get; set; } +
+ } + } +} -- cgit v1.3.1