dalenewman / OrchardCore.Transformalize

a transformalize module for orchard core
Apache License 2.0
13 stars 3 forks source link

Support Built in Connections #12

Closed dalenewman closed 3 years ago

dalenewman commented 3 years ago

It would be useful for arrangements to reference a built in connection (without knowing the provider or credentials).

e.g.

<connections>
   <!-- the connection below references the Orchard Core's site database which was determined at setup -->
   <add name="orchard" />
</connections>

In the same way that common connections are referenced by name, the orchard core's site connection could be used for reports, forms, or tasks. Side benefits are better security and less configuration.

Links

Notes

Tagged: @vlad2kgithub

dalenewman commented 3 years ago

Okay this works. I'm using a questionable approach to grab the database provider and connection string...

using(var cn = _dbConnectionAccessor.CreateConnection()) {
   connection.ConnectionString = cn.ConnectionString;
   connection.Provider = _store.Dialect.Name.ToLower();
}

Seems like I should be able to get this information without creating a connection.

dalenewman commented 3 years ago

Example...


<cfg name="Users">
   <connections>
      <add name="orchard" />
   </connections>
   <entities>
      <add name='UserIndex'>
        <fields>
          <add name="Id" type="int" primary-key="true"/>
          <add name="DocumentId" type="int" label="Doc Id" />
          <add name="NormalizedUserName" label="Username" length="255"/>
          <add name="NormalizedEmail" label="Email" length="255"/>
          <add name="IsEnabled" label="Enabled" type="bool"/>
        </fields>
      </add>
   </entities>
</cfg>```

Note: If you're using PostgreSql against this Orchard Core created table, you will have to add `enclose="true"` to the connection.  This is because Orchard double quotes all the identifiers it creates when using PostgreSql.