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/EntityCodeFile.cshtml | 37 +++++++--------------- 1 file changed, 11 insertions(+), 26 deletions(-) (limited to 'Software/Visual_Studio/Tango.CodeGeneration/Templates/EntityCodeFile.cshtml') diff --git a/Software/Visual_Studio/Tango.CodeGeneration/Templates/EntityCodeFile.cshtml b/Software/Visual_Studio/Tango.CodeGeneration/Templates/EntityCodeFile.cshtml index 709da7dda..001a2bb3f 100644 --- a/Software/Visual_Studio/Tango.CodeGeneration/Templates/EntityCodeFile.cshtml +++ b/Software/Visual_Studio/Tango.CodeGeneration/Templates/EntityCodeFile.cshtml @@ -1,13 +1,15 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using Tango.DAL.Remote.DB; namespace Tango.DAL.Observables { - [EntityFieldName("@(Model.TableName)")] - public partial class @(Model.Name) : ObservableEntity<@(Model.EntityName)> + [Table("@(Model.TableName)")] + public partial class @(Model.Name) : ObservableEntity { @foreach (var prop in Model.Fields) { @@ -16,8 +18,9 @@ namespace Tango.DAL.Observables /// /// Gets or sets the @(Model.Name.ToLower()) @(prop.Description). /// - [EntityFieldName("@(prop.FieldName)")] - public @(prop.Type) @(prop.Name) + @(!prop.Construct && !prop.Complex ? "[Column(\"" + prop.FieldName + "\")]" : "") + @(prop.IsForeignKey ? "[ForeignKey(\"" + prop.ForeignKeyName + "\")]" : "") + public @(prop.Construct || prop.Complex ? "virtual" : "") @(prop.Type) @(prop.Name) { get { return _@(prop.Name.ToLower()); } set { _@(prop.Name.ToLower()) = value; RaisePropertyChanged(nameof(@(prop.Name))); } @@ -29,32 +32,14 @@ namespace Tango.DAL.Observables /// Initializes a new instance of the class. /// public @(Model.Name)() : base() - { - Init(); - } - - /// - /// Initializes a new instance of the class. - /// - /// The entity. - public @(Model.Name)(@(Model.EntityName) entity) : base(entity) - { - Init(); - MapEntityToObservable(entity, this); - } - - /// - /// Initialize complex types. - /// - private void Init() { @foreach (var prop in Model.Fields) { if (prop.Construct) - { -
- @(prop.Name) = new @(prop.Type)(); -
+ { +
+ @(prop.Name) = new @(prop.Type)(); +
} } } -- cgit v1.3.1