Never Let A Opportunity Go to Waste
-
I think I would get flayed if I posted that much code in the lounge. :laugh: Congratulations to you.
Real programmers use butterflies
In American Texas, code poster flays you :D
Best, Sander Azure DevOps Succinctly (free eBook) Azure Serverless Succinctly (free eBook) Migrating Apps to the Cloud with Azure arrgh.js - Bringing LINQ to JavaScript
-
I found myself with nothing to do this week, so I decided to make a concerted effort to repair the significant code loss I suffered back in May/2020 with respect to my entity factory app. I think I'm happy once again with the model generation, so I figured I'd post some code the app generated for me. For those that have forgotten, EntityFactory will generate model (and optionally viewmodel) classes based on the selected table, view, and stored procedure (SQL server). What makes this app more functional than the ADO code generator is that it will generate an object for any stored proc that returns data, regardless of the method by which the data is returned (the ADO code generator refuses to work with stored procs that return data with dynamic sql, and re-generating code doesn't work in a number of spectacular ways). In the sample below, I turned on the generation of crud properties, just to exercise that part of the code. All of the code below was generated based on the returned schema for the indicated database source object. Processing took less than a second.
/==================================================================================================
// Source object: AEF2.dbo.Alerts (table)
// File generated: 2020.11.27, 01:03:07// This file was generated by EntityFactory. Do not modify this file. When regenerated, the file
// may be overwritten if it already exists (and EntityFactory was configured to overwrite existing
// files). Note that the generated class is "partial", so if you need to augment the generated
// code, create a new partial extension file and put your custom code in that new file.// The class name indicates the model (or viewmodel) class name prefix followed by the name of the
// original database object from which the class was generated.
//==================================================================================================using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;// Auto-incrementing column detected - added the following using to support standard C# attributes.
// If you haven't already, add a reference to System.ComponentModel.DataAnnotations to the
// applicable assembly in your application.
using System.ComponentModel.DataAnnotations;namespace Models
{
public partial class EntityAlerts
{
#region entity properties\[Key\] public int
CrudGet* CrudUpsert* CrudDelete* :D I was going to ask why you didn't use a MERGE for the UPSERT, but I already found out myself. Good stuff! :thumbsup:
Best, Sander Azure DevOps Succinctly (free eBook) Azure Serverless Succinctly (free eBook) Migrating Apps to the Cloud with Azure arrgh.js - Bringing LINQ to JavaScript
-
I think I would get flayed if I posted that much code in the lounge. :laugh: Congratulations to you.
Real programmers use butterflies
I don't see the problem with posting the output from a code generator, as long as you don't pose a question about it in the message. At that point, you're simply showing the output of an application. If anyone gives you grief, let me know - I'll set 'em straight. Note - I purposely chose a table that only has a few returned columns.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013 -
I don't see the problem with posting the output from a code generator, as long as you don't pose a question about it in the message. At that point, you're simply showing the output of an application. If anyone gives you grief, let me know - I'll set 'em straight. Note - I purposely chose a table that only has a few returned columns.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013I don't either, personally. I appreciated your comment, as I am a fan of code generation.
Real programmers use butterflies
-
CrudGet* CrudUpsert* CrudDelete* :D I was going to ask why you didn't use a MERGE for the UPSERT, but I already found out myself. Good stuff! :thumbsup:
Best, Sander Azure DevOps Succinctly (free eBook) Azure Serverless Succinctly (free eBook) Migrating Apps to the Cloud with Azure arrgh.js - Bringing LINQ to JavaScript
Sander Rossel wrote:
I was going to ask why you didn't use a MERGE for the UPSERT, but I already found out myself.
Using the
MERGE
function is fraught with danger, and it's easy to do it wrong. Furthermore, a MERGE operation is usually more complex, and typically uses several of the table's columns to determine whether or not an item should be updated. There's probably no way to generate it automagically that would be suitable in more than a small handful of instances. It is simply easier and more reliable to generate anUpsert
instead. The programmer can always extend the generated partial class and include a specific CRUDMerge property, so I think my bases are sufficiently covered. BTW, this is primary reason I'm writing this aapp - the existing tools don't create partial classes, and don't allow you to customize their implementation based on corporate requirements as far as coding style and framework component inclusion. For instance, you can specify your own implementation code forINotifyPropertyChanged,
andIDataErrrorInfo
interfaces in the generated viewmodel, and you can even specify the standardusing
statements for the model and viewmodel (although the usefulness of these would only benefit you if a given "standard" name space was removed from .Net at some point in the future). It's a cool app, and we're going to use it at work when we start our flagship application rewrite (whenever that's allowed to happen).".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013 -
Sander Rossel wrote:
I was going to ask why you didn't use a MERGE for the UPSERT, but I already found out myself.
Using the
MERGE
function is fraught with danger, and it's easy to do it wrong. Furthermore, a MERGE operation is usually more complex, and typically uses several of the table's columns to determine whether or not an item should be updated. There's probably no way to generate it automagically that would be suitable in more than a small handful of instances. It is simply easier and more reliable to generate anUpsert
instead. The programmer can always extend the generated partial class and include a specific CRUDMerge property, so I think my bases are sufficiently covered. BTW, this is primary reason I'm writing this aapp - the existing tools don't create partial classes, and don't allow you to customize their implementation based on corporate requirements as far as coding style and framework component inclusion. For instance, you can specify your own implementation code forINotifyPropertyChanged,
andIDataErrrorInfo
interfaces in the generated viewmodel, and you can even specify the standardusing
statements for the model and viewmodel (although the usefulness of these would only benefit you if a given "standard" name space was removed from .Net at some point in the future). It's a cool app, and we're going to use it at work when we start our flagship application rewrite (whenever that's allowed to happen).".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013#realJSOP wrote:
It's a cool app, and we're going to use it at work when we start our flagship application rewrite (whenever that's allowed to happen).
Good stuff! I've been using Entity Framework Core and love it so far. I just write my domain models, write my DB mapping and let EF sort out the rest. Not so nice when you get breaking changes and EF just drops a column (or table) instead of renaming and that sort of stuff :laugh: The queries it generates are pretty clean overall and I've gotten a lot better at predicating what they look like based on my LINQ query :)
Best, Sander Azure DevOps Succinctly (free eBook) Azure Serverless Succinctly (free eBook) Migrating Apps to the Cloud with Azure arrgh.js - Bringing LINQ to JavaScript
-
I think I would get flayed if I posted that much code in the lounge. :laugh: Congratulations to you.
Real programmers use butterflies
JSOP is a special case, a bit like OG, the Richards and you for that matter. People who contribute so much to the site that they have and deserve carte blanche. It is very rarely abused.
Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP
-
JSOP is a special case, a bit like OG, the Richards and you for that matter. People who contribute so much to the site that they have and deserve carte blanche. It is very rarely abused.
Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP
That's fair. I try not to abuse the forum myself but I'm a weirdo and social decorum is not always my best strength, even online. Even among other developers. :laugh:
Real programmers use butterflies
-
I found myself with nothing to do this week, so I decided to make a concerted effort to repair the significant code loss I suffered back in May/2020 with respect to my entity factory app. I think I'm happy once again with the model generation, so I figured I'd post some code the app generated for me. For those that have forgotten, EntityFactory will generate model (and optionally viewmodel) classes based on the selected table, view, and stored procedure (SQL server). What makes this app more functional than the ADO code generator is that it will generate an object for any stored proc that returns data, regardless of the method by which the data is returned (the ADO code generator refuses to work with stored procs that return data with dynamic sql, and re-generating code doesn't work in a number of spectacular ways). In the sample below, I turned on the generation of crud properties, just to exercise that part of the code. All of the code below was generated based on the returned schema for the indicated database source object. Processing took less than a second.
/==================================================================================================
// Source object: AEF2.dbo.Alerts (table)
// File generated: 2020.11.27, 01:03:07// This file was generated by EntityFactory. Do not modify this file. When regenerated, the file
// may be overwritten if it already exists (and EntityFactory was configured to overwrite existing
// files). Note that the generated class is "partial", so if you need to augment the generated
// code, create a new partial extension file and put your custom code in that new file.// The class name indicates the model (or viewmodel) class name prefix followed by the name of the
// original database object from which the class was generated.
//==================================================================================================using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;// Auto-incrementing column detected - added the following using to support standard C# attributes.
// If you haven't already, add a reference to System.ComponentModel.DataAnnotations to the
// applicable assembly in your application.
using System.ComponentModel.DataAnnotations;namespace Models
{
public partial class EntityAlerts
{
#region entity properties\[Key\] public int
The company I work for would flog you for using the
NOLOCK
hint in your SELECT statement. :)Kelly Herald Software Developer
-
The company I work for would flog you for using the
NOLOCK
hint in your SELECT statement. :)Kelly Herald Software Developer
Wehave simulateous access by thousands of users and dozens of stored procs, we have to do that because our queries take a few seconds.If we don't do it, we get errors.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013