Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. LINQ is fun!

LINQ is fun!

Scheduled Pinned Locked Moved The Lounge
csharpdatabaselinqcom
29 Posts 21 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Marc Clifton
    wrote on last edited by
    #1

    Especially when combined with extension methods and fluent-style methods.

    envvars
    .Municipalities()
    .Select(m => m.Fixups())
    .NotServiceAccess()
    .Where(m => m.VerifyConnection(_ => Log($"{m.Municipality}: {m.ConnectionString} => Connection failed.")))
    .Do(munis =>
    munis.SelectWith(m => M5.GetTableNames(AUDIT_SCHEMA, m.ConnectionString), (m, with) => (auditableEntities.NotIn(with, s => s.TableName.ToLower(), t => t.ToLower()), m))
    .ForEach(q => q
    .Iterate((t, m) =>
    t
    .Do(_ => Log($"{m.Municipality}: {t.TableName} => Audit table missing"))
    .GenerateMissingAuditTableSql(m)
    .Execute(m.ConnectionString, (sql, e) => Log($"{m.Municipality}: {t.TableName} => {e.Message}\r\nFailed to execute SQL: {sql.ToString()}"))
    )))
    .Do(munis =>
    {
    munis.SelectWith(m => M5.GetTableNames(AUDIT_SCHEMA, m.ConnectionString), (m, with) => (auditableEntities.In(with, s => s.TableName.ToLower(), t => t.ToLower()), m))
    .ForEach(q => q
    .Iterate((t, m) =>
    {
    Log($"{m.Municipality}: {t.TableName} => Checking...");
    var entityColumns = M5.GetColumnList(DBO_SCHEMA, m.ConnectionString, t.TableName);
    var auditColumns = M5.GetColumnList(AUDIT_SCHEMA, m.ConnectionString, t.TableName);

                    entityColumns.NotIn(auditColumns, s => s.Name.ToLower(), f => f.Name.ToLower())
                        .DoIf(q2 => q2.Count() > 0, q3 => Log($"  {q3.Count()} missing fields"))
                        .ForEach(f =>
                        {
                            Log($"  {m.Municipality}: {t.TableName} => Field {f} missing in audit table");
    
                            f
                                .GenerateMissingColumnSql(m, AUDIT\_SCHEMA, t.TableName)
                                .Execute(m.ConnectionString, (sql, e) => Log($"{m.Municipality}: {t.TableName} => {e.Message}\\r\\nFailed to execute SQL: {sql.ToString()}"));
                        });
                }));
        });
    

    This is a custom "one line" function that creates missing audit tables or adds the missing columns that the entity defines but someone forgot to add to the audit table. :-D

    Latest Articles:
    Client-Side Type-Based Publish

    D L C M Sander RosselS 15 Replies Last reply
    0
    • M Marc Clifton

      Especially when combined with extension methods and fluent-style methods.

      envvars
      .Municipalities()
      .Select(m => m.Fixups())
      .NotServiceAccess()
      .Where(m => m.VerifyConnection(_ => Log($"{m.Municipality}: {m.ConnectionString} => Connection failed.")))
      .Do(munis =>
      munis.SelectWith(m => M5.GetTableNames(AUDIT_SCHEMA, m.ConnectionString), (m, with) => (auditableEntities.NotIn(with, s => s.TableName.ToLower(), t => t.ToLower()), m))
      .ForEach(q => q
      .Iterate((t, m) =>
      t
      .Do(_ => Log($"{m.Municipality}: {t.TableName} => Audit table missing"))
      .GenerateMissingAuditTableSql(m)
      .Execute(m.ConnectionString, (sql, e) => Log($"{m.Municipality}: {t.TableName} => {e.Message}\r\nFailed to execute SQL: {sql.ToString()}"))
      )))
      .Do(munis =>
      {
      munis.SelectWith(m => M5.GetTableNames(AUDIT_SCHEMA, m.ConnectionString), (m, with) => (auditableEntities.In(with, s => s.TableName.ToLower(), t => t.ToLower()), m))
      .ForEach(q => q
      .Iterate((t, m) =>
      {
      Log($"{m.Municipality}: {t.TableName} => Checking...");
      var entityColumns = M5.GetColumnList(DBO_SCHEMA, m.ConnectionString, t.TableName);
      var auditColumns = M5.GetColumnList(AUDIT_SCHEMA, m.ConnectionString, t.TableName);

                      entityColumns.NotIn(auditColumns, s => s.Name.ToLower(), f => f.Name.ToLower())
                          .DoIf(q2 => q2.Count() > 0, q3 => Log($"  {q3.Count()} missing fields"))
                          .ForEach(f =>
                          {
                              Log($"  {m.Municipality}: {t.TableName} => Field {f} missing in audit table");
      
                              f
                                  .GenerateMissingColumnSql(m, AUDIT\_SCHEMA, t.TableName)
                                  .Execute(m.ConnectionString, (sql, e) => Log($"{m.Municipality}: {t.TableName} => {e.Message}\\r\\nFailed to execute SQL: {sql.ToString()}"));
                          });
                  }));
          });
      

      This is a custom "one line" function that creates missing audit tables or adds the missing columns that the entity defines but someone forgot to add to the audit table. :-D

      Latest Articles:
      Client-Side Type-Based Publish

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      That's ... uhh ... a rather impressive abuse of LINQ that screams "oh hell no! I'm not getting anywhere near that to support it!"

      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
      Dave Kreskowiak

      1 Reply Last reply
      0
      • M Marc Clifton

        Especially when combined with extension methods and fluent-style methods.

        envvars
        .Municipalities()
        .Select(m => m.Fixups())
        .NotServiceAccess()
        .Where(m => m.VerifyConnection(_ => Log($"{m.Municipality}: {m.ConnectionString} => Connection failed.")))
        .Do(munis =>
        munis.SelectWith(m => M5.GetTableNames(AUDIT_SCHEMA, m.ConnectionString), (m, with) => (auditableEntities.NotIn(with, s => s.TableName.ToLower(), t => t.ToLower()), m))
        .ForEach(q => q
        .Iterate((t, m) =>
        t
        .Do(_ => Log($"{m.Municipality}: {t.TableName} => Audit table missing"))
        .GenerateMissingAuditTableSql(m)
        .Execute(m.ConnectionString, (sql, e) => Log($"{m.Municipality}: {t.TableName} => {e.Message}\r\nFailed to execute SQL: {sql.ToString()}"))
        )))
        .Do(munis =>
        {
        munis.SelectWith(m => M5.GetTableNames(AUDIT_SCHEMA, m.ConnectionString), (m, with) => (auditableEntities.In(with, s => s.TableName.ToLower(), t => t.ToLower()), m))
        .ForEach(q => q
        .Iterate((t, m) =>
        {
        Log($"{m.Municipality}: {t.TableName} => Checking...");
        var entityColumns = M5.GetColumnList(DBO_SCHEMA, m.ConnectionString, t.TableName);
        var auditColumns = M5.GetColumnList(AUDIT_SCHEMA, m.ConnectionString, t.TableName);

                        entityColumns.NotIn(auditColumns, s => s.Name.ToLower(), f => f.Name.ToLower())
                            .DoIf(q2 => q2.Count() > 0, q3 => Log($"  {q3.Count()} missing fields"))
                            .ForEach(f =>
                            {
                                Log($"  {m.Municipality}: {t.TableName} => Field {f} missing in audit table");
        
                                f
                                    .GenerateMissingColumnSql(m, AUDIT\_SCHEMA, t.TableName)
                                    .Execute(m.ConnectionString, (sql, e) => Log($"{m.Municipality}: {t.TableName} => {e.Message}\\r\\nFailed to execute SQL: {sql.ToString()}"));
                            });
                    }));
            });
        

        This is a custom "one line" function that creates missing audit tables or adds the missing columns that the entity defines but someone forgot to add to the audit table. :-D

        Latest Articles:
        Client-Side Type-Based Publish

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Years ago, my teacher would say that any program in C++ "could" be written in a single line, and that one definitely shouldn't.

        Bastard Programmer from Hell :suss: "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

        P 1 Reply Last reply
        0
        • M Marc Clifton

          Especially when combined with extension methods and fluent-style methods.

          envvars
          .Municipalities()
          .Select(m => m.Fixups())
          .NotServiceAccess()
          .Where(m => m.VerifyConnection(_ => Log($"{m.Municipality}: {m.ConnectionString} => Connection failed.")))
          .Do(munis =>
          munis.SelectWith(m => M5.GetTableNames(AUDIT_SCHEMA, m.ConnectionString), (m, with) => (auditableEntities.NotIn(with, s => s.TableName.ToLower(), t => t.ToLower()), m))
          .ForEach(q => q
          .Iterate((t, m) =>
          t
          .Do(_ => Log($"{m.Municipality}: {t.TableName} => Audit table missing"))
          .GenerateMissingAuditTableSql(m)
          .Execute(m.ConnectionString, (sql, e) => Log($"{m.Municipality}: {t.TableName} => {e.Message}\r\nFailed to execute SQL: {sql.ToString()}"))
          )))
          .Do(munis =>
          {
          munis.SelectWith(m => M5.GetTableNames(AUDIT_SCHEMA, m.ConnectionString), (m, with) => (auditableEntities.In(with, s => s.TableName.ToLower(), t => t.ToLower()), m))
          .ForEach(q => q
          .Iterate((t, m) =>
          {
          Log($"{m.Municipality}: {t.TableName} => Checking...");
          var entityColumns = M5.GetColumnList(DBO_SCHEMA, m.ConnectionString, t.TableName);
          var auditColumns = M5.GetColumnList(AUDIT_SCHEMA, m.ConnectionString, t.TableName);

                          entityColumns.NotIn(auditColumns, s => s.Name.ToLower(), f => f.Name.ToLower())
                              .DoIf(q2 => q2.Count() > 0, q3 => Log($"  {q3.Count()} missing fields"))
                              .ForEach(f =>
                              {
                                  Log($"  {m.Municipality}: {t.TableName} => Field {f} missing in audit table");
          
                                  f
                                      .GenerateMissingColumnSql(m, AUDIT\_SCHEMA, t.TableName)
                                      .Execute(m.ConnectionString, (sql, e) => Log($"{m.Municipality}: {t.TableName} => {e.Message}\\r\\nFailed to execute SQL: {sql.ToString()}"));
                              });
                      }));
              });
          

          This is a custom "one line" function that creates missing audit tables or adds the missing columns that the entity defines but someone forgot to add to the audit table. :-D

          Latest Articles:
          Client-Side Type-Based Publish

          C Offline
          C Offline
          Chris Losinger
          wrote on last edited by
          #4

          looks a lot like the kind of horrors i find in Typescript...

          1 Reply Last reply
          0
          • M Marc Clifton

            Especially when combined with extension methods and fluent-style methods.

            envvars
            .Municipalities()
            .Select(m => m.Fixups())
            .NotServiceAccess()
            .Where(m => m.VerifyConnection(_ => Log($"{m.Municipality}: {m.ConnectionString} => Connection failed.")))
            .Do(munis =>
            munis.SelectWith(m => M5.GetTableNames(AUDIT_SCHEMA, m.ConnectionString), (m, with) => (auditableEntities.NotIn(with, s => s.TableName.ToLower(), t => t.ToLower()), m))
            .ForEach(q => q
            .Iterate((t, m) =>
            t
            .Do(_ => Log($"{m.Municipality}: {t.TableName} => Audit table missing"))
            .GenerateMissingAuditTableSql(m)
            .Execute(m.ConnectionString, (sql, e) => Log($"{m.Municipality}: {t.TableName} => {e.Message}\r\nFailed to execute SQL: {sql.ToString()}"))
            )))
            .Do(munis =>
            {
            munis.SelectWith(m => M5.GetTableNames(AUDIT_SCHEMA, m.ConnectionString), (m, with) => (auditableEntities.In(with, s => s.TableName.ToLower(), t => t.ToLower()), m))
            .ForEach(q => q
            .Iterate((t, m) =>
            {
            Log($"{m.Municipality}: {t.TableName} => Checking...");
            var entityColumns = M5.GetColumnList(DBO_SCHEMA, m.ConnectionString, t.TableName);
            var auditColumns = M5.GetColumnList(AUDIT_SCHEMA, m.ConnectionString, t.TableName);

                            entityColumns.NotIn(auditColumns, s => s.Name.ToLower(), f => f.Name.ToLower())
                                .DoIf(q2 => q2.Count() > 0, q3 => Log($"  {q3.Count()} missing fields"))
                                .ForEach(f =>
                                {
                                    Log($"  {m.Municipality}: {t.TableName} => Field {f} missing in audit table");
            
                                    f
                                        .GenerateMissingColumnSql(m, AUDIT\_SCHEMA, t.TableName)
                                        .Execute(m.ConnectionString, (sql, e) => Log($"{m.Municipality}: {t.TableName} => {e.Message}\\r\\nFailed to execute SQL: {sql.ToString()}"));
                                });
                        }));
                });
            

            This is a custom "one line" function that creates missing audit tables or adds the missing columns that the entity defines but someone forgot to add to the audit table. :-D

            Latest Articles:
            Client-Side Type-Based Publish

            M Offline
            M Offline
            Maximilien
            wrote on last edited by
            #5

            (serious) Is there a reason to write ugly code like that ? Is it more efficient ? If I was looking at code like that I would probably send it back after code review. :confused:

            I'd rather be phishing!

            D M O 3 Replies Last reply
            0
            • M Marc Clifton

              Especially when combined with extension methods and fluent-style methods.

              envvars
              .Municipalities()
              .Select(m => m.Fixups())
              .NotServiceAccess()
              .Where(m => m.VerifyConnection(_ => Log($"{m.Municipality}: {m.ConnectionString} => Connection failed.")))
              .Do(munis =>
              munis.SelectWith(m => M5.GetTableNames(AUDIT_SCHEMA, m.ConnectionString), (m, with) => (auditableEntities.NotIn(with, s => s.TableName.ToLower(), t => t.ToLower()), m))
              .ForEach(q => q
              .Iterate((t, m) =>
              t
              .Do(_ => Log($"{m.Municipality}: {t.TableName} => Audit table missing"))
              .GenerateMissingAuditTableSql(m)
              .Execute(m.ConnectionString, (sql, e) => Log($"{m.Municipality}: {t.TableName} => {e.Message}\r\nFailed to execute SQL: {sql.ToString()}"))
              )))
              .Do(munis =>
              {
              munis.SelectWith(m => M5.GetTableNames(AUDIT_SCHEMA, m.ConnectionString), (m, with) => (auditableEntities.In(with, s => s.TableName.ToLower(), t => t.ToLower()), m))
              .ForEach(q => q
              .Iterate((t, m) =>
              {
              Log($"{m.Municipality}: {t.TableName} => Checking...");
              var entityColumns = M5.GetColumnList(DBO_SCHEMA, m.ConnectionString, t.TableName);
              var auditColumns = M5.GetColumnList(AUDIT_SCHEMA, m.ConnectionString, t.TableName);

                              entityColumns.NotIn(auditColumns, s => s.Name.ToLower(), f => f.Name.ToLower())
                                  .DoIf(q2 => q2.Count() > 0, q3 => Log($"  {q3.Count()} missing fields"))
                                  .ForEach(f =>
                                  {
                                      Log($"  {m.Municipality}: {t.TableName} => Field {f} missing in audit table");
              
                                      f
                                          .GenerateMissingColumnSql(m, AUDIT\_SCHEMA, t.TableName)
                                          .Execute(m.ConnectionString, (sql, e) => Log($"{m.Municipality}: {t.TableName} => {e.Message}\\r\\nFailed to execute SQL: {sql.ToString()}"));
                                  });
                          }));
                  });
              

              This is a custom "one line" function that creates missing audit tables or adds the missing columns that the entity defines but someone forgot to add to the audit table. :-D

              Latest Articles:
              Client-Side Type-Based Publish

              Sander RosselS Offline
              Sander RosselS Offline
              Sander Rossel
              wrote on last edited by
              #6

              @code-witch really loves LINQ too! :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

              1 Reply Last reply
              0
              • M Marc Clifton

                Especially when combined with extension methods and fluent-style methods.

                envvars
                .Municipalities()
                .Select(m => m.Fixups())
                .NotServiceAccess()
                .Where(m => m.VerifyConnection(_ => Log($"{m.Municipality}: {m.ConnectionString} => Connection failed.")))
                .Do(munis =>
                munis.SelectWith(m => M5.GetTableNames(AUDIT_SCHEMA, m.ConnectionString), (m, with) => (auditableEntities.NotIn(with, s => s.TableName.ToLower(), t => t.ToLower()), m))
                .ForEach(q => q
                .Iterate((t, m) =>
                t
                .Do(_ => Log($"{m.Municipality}: {t.TableName} => Audit table missing"))
                .GenerateMissingAuditTableSql(m)
                .Execute(m.ConnectionString, (sql, e) => Log($"{m.Municipality}: {t.TableName} => {e.Message}\r\nFailed to execute SQL: {sql.ToString()}"))
                )))
                .Do(munis =>
                {
                munis.SelectWith(m => M5.GetTableNames(AUDIT_SCHEMA, m.ConnectionString), (m, with) => (auditableEntities.In(with, s => s.TableName.ToLower(), t => t.ToLower()), m))
                .ForEach(q => q
                .Iterate((t, m) =>
                {
                Log($"{m.Municipality}: {t.TableName} => Checking...");
                var entityColumns = M5.GetColumnList(DBO_SCHEMA, m.ConnectionString, t.TableName);
                var auditColumns = M5.GetColumnList(AUDIT_SCHEMA, m.ConnectionString, t.TableName);

                                entityColumns.NotIn(auditColumns, s => s.Name.ToLower(), f => f.Name.ToLower())
                                    .DoIf(q2 => q2.Count() > 0, q3 => Log($"  {q3.Count()} missing fields"))
                                    .ForEach(f =>
                                    {
                                        Log($"  {m.Municipality}: {t.TableName} => Field {f} missing in audit table");
                
                                        f
                                            .GenerateMissingColumnSql(m, AUDIT\_SCHEMA, t.TableName)
                                            .Execute(m.ConnectionString, (sql, e) => Log($"{m.Municipality}: {t.TableName} => {e.Message}\\r\\nFailed to execute SQL: {sql.ToString()}"));
                                    });
                            }));
                    });
                

                This is a custom "one line" function that creates missing audit tables or adds the missing columns that the entity defines but someone forgot to add to the audit table. :-D

                Latest Articles:
                Client-Side Type-Based Publish

                F Offline
                F Offline
                Forogar
                wrote on last edited by
                #7

                Beautiful! ;P

                - I would love to change the world, but they won’t give me the source code.

                1 Reply Last reply
                0
                • L Lost User

                  Years ago, my teacher would say that any program in C++ "could" be written in a single line, and that one definitely shouldn't.

                  Bastard Programmer from Hell :suss: "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                  P Offline
                  P Offline
                  PIEBALDconsult
                  wrote on last edited by
                  #8

                  In high-level languages there are no lines -- only statements.

                  L 1 Reply Last reply
                  0
                  • M Maximilien

                    (serious) Is there a reason to write ugly code like that ? Is it more efficient ? If I was looking at code like that I would probably send it back after code review. :confused:

                    I'd rather be phishing!

                    D Offline
                    D Offline
                    Dan Neely
                    wrote on last edited by
                    #9

                    Someone has a linq shaped hammer. All the world is a nail. :doh:

                    Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

                    1 Reply Last reply
                    0
                    • P PIEBALDconsult

                      In high-level languages there are no lines -- only statements.

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      So; you'd like to see one statement per line, or all off them in a single line?

                      Bastard Programmer from Hell :suss: "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                      1 Reply Last reply
                      0
                      • M Marc Clifton

                        Especially when combined with extension methods and fluent-style methods.

                        envvars
                        .Municipalities()
                        .Select(m => m.Fixups())
                        .NotServiceAccess()
                        .Where(m => m.VerifyConnection(_ => Log($"{m.Municipality}: {m.ConnectionString} => Connection failed.")))
                        .Do(munis =>
                        munis.SelectWith(m => M5.GetTableNames(AUDIT_SCHEMA, m.ConnectionString), (m, with) => (auditableEntities.NotIn(with, s => s.TableName.ToLower(), t => t.ToLower()), m))
                        .ForEach(q => q
                        .Iterate((t, m) =>
                        t
                        .Do(_ => Log($"{m.Municipality}: {t.TableName} => Audit table missing"))
                        .GenerateMissingAuditTableSql(m)
                        .Execute(m.ConnectionString, (sql, e) => Log($"{m.Municipality}: {t.TableName} => {e.Message}\r\nFailed to execute SQL: {sql.ToString()}"))
                        )))
                        .Do(munis =>
                        {
                        munis.SelectWith(m => M5.GetTableNames(AUDIT_SCHEMA, m.ConnectionString), (m, with) => (auditableEntities.In(with, s => s.TableName.ToLower(), t => t.ToLower()), m))
                        .ForEach(q => q
                        .Iterate((t, m) =>
                        {
                        Log($"{m.Municipality}: {t.TableName} => Checking...");
                        var entityColumns = M5.GetColumnList(DBO_SCHEMA, m.ConnectionString, t.TableName);
                        var auditColumns = M5.GetColumnList(AUDIT_SCHEMA, m.ConnectionString, t.TableName);

                                        entityColumns.NotIn(auditColumns, s => s.Name.ToLower(), f => f.Name.ToLower())
                                            .DoIf(q2 => q2.Count() > 0, q3 => Log($"  {q3.Count()} missing fields"))
                                            .ForEach(f =>
                                            {
                                                Log($"  {m.Municipality}: {t.TableName} => Field {f} missing in audit table");
                        
                                                f
                                                    .GenerateMissingColumnSql(m, AUDIT\_SCHEMA, t.TableName)
                                                    .Execute(m.ConnectionString, (sql, e) => Log($"{m.Municipality}: {t.TableName} => {e.Message}\\r\\nFailed to execute SQL: {sql.ToString()}"));
                                            });
                                    }));
                            });
                        

                        This is a custom "one line" function that creates missing audit tables or adds the missing columns that the entity defines but someone forgot to add to the audit table. :-D

                        Latest Articles:
                        Client-Side Type-Based Publish

                        S Offline
                        S Offline
                        Stepan Hakobyan
                        wrote on last edited by
                        #11

                        Functional programming )))

                        D M 2 Replies Last reply
                        0
                        • M Marc Clifton

                          Especially when combined with extension methods and fluent-style methods.

                          envvars
                          .Municipalities()
                          .Select(m => m.Fixups())
                          .NotServiceAccess()
                          .Where(m => m.VerifyConnection(_ => Log($"{m.Municipality}: {m.ConnectionString} => Connection failed.")))
                          .Do(munis =>
                          munis.SelectWith(m => M5.GetTableNames(AUDIT_SCHEMA, m.ConnectionString), (m, with) => (auditableEntities.NotIn(with, s => s.TableName.ToLower(), t => t.ToLower()), m))
                          .ForEach(q => q
                          .Iterate((t, m) =>
                          t
                          .Do(_ => Log($"{m.Municipality}: {t.TableName} => Audit table missing"))
                          .GenerateMissingAuditTableSql(m)
                          .Execute(m.ConnectionString, (sql, e) => Log($"{m.Municipality}: {t.TableName} => {e.Message}\r\nFailed to execute SQL: {sql.ToString()}"))
                          )))
                          .Do(munis =>
                          {
                          munis.SelectWith(m => M5.GetTableNames(AUDIT_SCHEMA, m.ConnectionString), (m, with) => (auditableEntities.In(with, s => s.TableName.ToLower(), t => t.ToLower()), m))
                          .ForEach(q => q
                          .Iterate((t, m) =>
                          {
                          Log($"{m.Municipality}: {t.TableName} => Checking...");
                          var entityColumns = M5.GetColumnList(DBO_SCHEMA, m.ConnectionString, t.TableName);
                          var auditColumns = M5.GetColumnList(AUDIT_SCHEMA, m.ConnectionString, t.TableName);

                                          entityColumns.NotIn(auditColumns, s => s.Name.ToLower(), f => f.Name.ToLower())
                                              .DoIf(q2 => q2.Count() > 0, q3 => Log($"  {q3.Count()} missing fields"))
                                              .ForEach(f =>
                                              {
                                                  Log($"  {m.Municipality}: {t.TableName} => Field {f} missing in audit table");
                          
                                                  f
                                                      .GenerateMissingColumnSql(m, AUDIT\_SCHEMA, t.TableName)
                                                      .Execute(m.ConnectionString, (sql, e) => Log($"{m.Municipality}: {t.TableName} => {e.Message}\\r\\nFailed to execute SQL: {sql.ToString()}"));
                                              });
                                      }));
                              });
                          

                          This is a custom "one line" function that creates missing audit tables or adds the missing columns that the entity defines but someone forgot to add to the audit table. :-D

                          Latest Articles:
                          Client-Side Type-Based Publish

                          D Offline
                          D Offline
                          den2k88
                          wrote on last edited by
                          #12

                          I read it aloud and accidentally summoned and eldritch horror. Please provide the unsummon chant.

                          GCS d--(d+) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

                          Richard DeemingR M D 3 Replies Last reply
                          0
                          • S Stepan Hakobyan

                            Functional programming )))

                            D Offline
                            D Offline
                            den2k88
                            wrote on last edited by
                            #13

                            stepan hakobyan wrote:

                            Functional programming )))

                            For dysfunctional programmers :D

                            GCS d--(d+) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

                            1 Reply Last reply
                            0
                            • D den2k88

                              I read it aloud and accidentally summoned and eldritch horror. Please provide the unsummon chant.

                              GCS d--(d+) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

                              Richard DeemingR Offline
                              Richard DeemingR Offline
                              Richard Deeming
                              wrote on last edited by
                              #14

                              Give Bob[^] a call. :)


                              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                              "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                              1 Reply Last reply
                              0
                              • S Stepan Hakobyan

                                Functional programming )))

                                M Offline
                                M Offline
                                Marc Clifton
                                wrote on last edited by
                                #15

                                stepan hakobyan wrote:

                                Functional programming )))

                                Yes! That was the point of the experiment.

                                Latest Articles:
                                Client-Side Type-Based Publisher/Subscriber, Exploring Synchronous, "Event-ed", and Worker Thread Subscriptions

                                1 Reply Last reply
                                0
                                • M Maximilien

                                  (serious) Is there a reason to write ugly code like that ? Is it more efficient ? If I was looking at code like that I would probably send it back after code review. :confused:

                                  I'd rather be phishing!

                                  M Offline
                                  M Offline
                                  Marc Clifton
                                  wrote on last edited by
                                  #16

                                  Maximilien wrote:

                                  Is there a reason to write ugly code like that ?

                                  I was curious to what extent, ok, extreme, I could go. One of the things I love about functional programming is the pipe operators |> and <| which have no equivalent in C#, the best one can do is the dot operator. So I wanted to play with the concept, see how far I could take it, what extension methods I needed to create to maintain the "continuation", how hard it would be to debug, and if the result looked in any way maintainable. One of the things I discovered is that, as usual, wrapping simple things like "where" expressions into a named extension method improves readability but potentially decreases the "well, how is that actually accomplished" immediate comprehension, and naming can be quite difficult when creating bizarre functions that iterate over a collection and pass in both the collection item and some other pre-computed value. So consider it a "thought experiment" in actual implementation. ;)

                                  Latest Articles:
                                  Client-Side Type-Based Publisher/Subscriber, Exploring Synchronous, "Event-ed", and Worker Thread Subscriptions

                                  D 1 Reply Last reply
                                  0
                                  • D den2k88

                                    I read it aloud and accidentally summoned and eldritch horror. Please provide the unsummon chant.

                                    GCS d--(d+) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

                                    M Offline
                                    M Offline
                                    Marc Clifton
                                    wrote on last edited by
                                    #17

                                    den2k88 wrote:

                                    Please provide the unsummon chant.

                                    You really do not want to see the one-liner for that! It summons several other beasts to defeat the eldritch horror, then you have those beasts to contend with, which requires summoning more beasts -- recursive stack overflow exception!

                                    Latest Articles:
                                    Client-Side Type-Based Publisher/Subscriber, Exploring Synchronous, "Event-ed", and Worker Thread Subscriptions

                                    1 Reply Last reply
                                    0
                                    • M Marc Clifton

                                      Especially when combined with extension methods and fluent-style methods.

                                      envvars
                                      .Municipalities()
                                      .Select(m => m.Fixups())
                                      .NotServiceAccess()
                                      .Where(m => m.VerifyConnection(_ => Log($"{m.Municipality}: {m.ConnectionString} => Connection failed.")))
                                      .Do(munis =>
                                      munis.SelectWith(m => M5.GetTableNames(AUDIT_SCHEMA, m.ConnectionString), (m, with) => (auditableEntities.NotIn(with, s => s.TableName.ToLower(), t => t.ToLower()), m))
                                      .ForEach(q => q
                                      .Iterate((t, m) =>
                                      t
                                      .Do(_ => Log($"{m.Municipality}: {t.TableName} => Audit table missing"))
                                      .GenerateMissingAuditTableSql(m)
                                      .Execute(m.ConnectionString, (sql, e) => Log($"{m.Municipality}: {t.TableName} => {e.Message}\r\nFailed to execute SQL: {sql.ToString()}"))
                                      )))
                                      .Do(munis =>
                                      {
                                      munis.SelectWith(m => M5.GetTableNames(AUDIT_SCHEMA, m.ConnectionString), (m, with) => (auditableEntities.In(with, s => s.TableName.ToLower(), t => t.ToLower()), m))
                                      .ForEach(q => q
                                      .Iterate((t, m) =>
                                      {
                                      Log($"{m.Municipality}: {t.TableName} => Checking...");
                                      var entityColumns = M5.GetColumnList(DBO_SCHEMA, m.ConnectionString, t.TableName);
                                      var auditColumns = M5.GetColumnList(AUDIT_SCHEMA, m.ConnectionString, t.TableName);

                                                      entityColumns.NotIn(auditColumns, s => s.Name.ToLower(), f => f.Name.ToLower())
                                                          .DoIf(q2 => q2.Count() > 0, q3 => Log($"  {q3.Count()} missing fields"))
                                                          .ForEach(f =>
                                                          {
                                                              Log($"  {m.Municipality}: {t.TableName} => Field {f} missing in audit table");
                                      
                                                              f
                                                                  .GenerateMissingColumnSql(m, AUDIT\_SCHEMA, t.TableName)
                                                                  .Execute(m.ConnectionString, (sql, e) => Log($"{m.Municipality}: {t.TableName} => {e.Message}\\r\\nFailed to execute SQL: {sql.ToString()}"));
                                                          });
                                                  }));
                                          });
                                      

                                      This is a custom "one line" function that creates missing audit tables or adds the missing columns that the entity defines but someone forgot to add to the audit table. :-D

                                      Latest Articles:
                                      Client-Side Type-Based Publish

                                      K Offline
                                      K Offline
                                      KateAshman
                                      wrote on last edited by
                                      #18

                                      Why? Who hurt you? :-D

                                      1 Reply Last reply
                                      0
                                      • M Marc Clifton

                                        Especially when combined with extension methods and fluent-style methods.

                                        envvars
                                        .Municipalities()
                                        .Select(m => m.Fixups())
                                        .NotServiceAccess()
                                        .Where(m => m.VerifyConnection(_ => Log($"{m.Municipality}: {m.ConnectionString} => Connection failed.")))
                                        .Do(munis =>
                                        munis.SelectWith(m => M5.GetTableNames(AUDIT_SCHEMA, m.ConnectionString), (m, with) => (auditableEntities.NotIn(with, s => s.TableName.ToLower(), t => t.ToLower()), m))
                                        .ForEach(q => q
                                        .Iterate((t, m) =>
                                        t
                                        .Do(_ => Log($"{m.Municipality}: {t.TableName} => Audit table missing"))
                                        .GenerateMissingAuditTableSql(m)
                                        .Execute(m.ConnectionString, (sql, e) => Log($"{m.Municipality}: {t.TableName} => {e.Message}\r\nFailed to execute SQL: {sql.ToString()}"))
                                        )))
                                        .Do(munis =>
                                        {
                                        munis.SelectWith(m => M5.GetTableNames(AUDIT_SCHEMA, m.ConnectionString), (m, with) => (auditableEntities.In(with, s => s.TableName.ToLower(), t => t.ToLower()), m))
                                        .ForEach(q => q
                                        .Iterate((t, m) =>
                                        {
                                        Log($"{m.Municipality}: {t.TableName} => Checking...");
                                        var entityColumns = M5.GetColumnList(DBO_SCHEMA, m.ConnectionString, t.TableName);
                                        var auditColumns = M5.GetColumnList(AUDIT_SCHEMA, m.ConnectionString, t.TableName);

                                                        entityColumns.NotIn(auditColumns, s => s.Name.ToLower(), f => f.Name.ToLower())
                                                            .DoIf(q2 => q2.Count() > 0, q3 => Log($"  {q3.Count()} missing fields"))
                                                            .ForEach(f =>
                                                            {
                                                                Log($"  {m.Municipality}: {t.TableName} => Field {f} missing in audit table");
                                        
                                                                f
                                                                    .GenerateMissingColumnSql(m, AUDIT\_SCHEMA, t.TableName)
                                                                    .Execute(m.ConnectionString, (sql, e) => Log($"{m.Municipality}: {t.TableName} => {e.Message}\\r\\nFailed to execute SQL: {sql.ToString()}"));
                                                            });
                                                    }));
                                            });
                                        

                                        This is a custom "one line" function that creates missing audit tables or adds the missing columns that the entity defines but someone forgot to add to the audit table. :-D

                                        Latest Articles:
                                        Client-Side Type-Based Publish

                                        J Offline
                                        J Offline
                                        jarvisa
                                        wrote on last edited by
                                        #19

                                        Strictly speaking, this is not LINQ. LINQ stands for Language-Integrated Query and is a query language that can be embedded within C#. You have written C# code using the classes that support LINQ. As an exercise, try rewriting your code using LINQ.

                                        1 Reply Last reply
                                        0
                                        • M Marc Clifton

                                          Especially when combined with extension methods and fluent-style methods.

                                          envvars
                                          .Municipalities()
                                          .Select(m => m.Fixups())
                                          .NotServiceAccess()
                                          .Where(m => m.VerifyConnection(_ => Log($"{m.Municipality}: {m.ConnectionString} => Connection failed.")))
                                          .Do(munis =>
                                          munis.SelectWith(m => M5.GetTableNames(AUDIT_SCHEMA, m.ConnectionString), (m, with) => (auditableEntities.NotIn(with, s => s.TableName.ToLower(), t => t.ToLower()), m))
                                          .ForEach(q => q
                                          .Iterate((t, m) =>
                                          t
                                          .Do(_ => Log($"{m.Municipality}: {t.TableName} => Audit table missing"))
                                          .GenerateMissingAuditTableSql(m)
                                          .Execute(m.ConnectionString, (sql, e) => Log($"{m.Municipality}: {t.TableName} => {e.Message}\r\nFailed to execute SQL: {sql.ToString()}"))
                                          )))
                                          .Do(munis =>
                                          {
                                          munis.SelectWith(m => M5.GetTableNames(AUDIT_SCHEMA, m.ConnectionString), (m, with) => (auditableEntities.In(with, s => s.TableName.ToLower(), t => t.ToLower()), m))
                                          .ForEach(q => q
                                          .Iterate((t, m) =>
                                          {
                                          Log($"{m.Municipality}: {t.TableName} => Checking...");
                                          var entityColumns = M5.GetColumnList(DBO_SCHEMA, m.ConnectionString, t.TableName);
                                          var auditColumns = M5.GetColumnList(AUDIT_SCHEMA, m.ConnectionString, t.TableName);

                                                          entityColumns.NotIn(auditColumns, s => s.Name.ToLower(), f => f.Name.ToLower())
                                                              .DoIf(q2 => q2.Count() > 0, q3 => Log($"  {q3.Count()} missing fields"))
                                                              .ForEach(f =>
                                                              {
                                                                  Log($"  {m.Municipality}: {t.TableName} => Field {f} missing in audit table");
                                          
                                                                  f
                                                                      .GenerateMissingColumnSql(m, AUDIT\_SCHEMA, t.TableName)
                                                                      .Execute(m.ConnectionString, (sql, e) => Log($"{m.Municipality}: {t.TableName} => {e.Message}\\r\\nFailed to execute SQL: {sql.ToString()}"));
                                                              });
                                                      }));
                                              });
                                          

                                          This is a custom "one line" function that creates missing audit tables or adds the missing columns that the entity defines but someone forgot to add to the audit table. :-D

                                          Latest Articles:
                                          Client-Side Type-Based Publish

                                          A Offline
                                          A Offline
                                          Andrey Logunov
                                          wrote on last edited by
                                          #20

                                          Still too many ";"

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups