Comments (7)
Can you explain what would you like to achieve, with an example?
from helpful-libraries.
For some reason, it's essential to store specific data (called BigData
below) isolated from the Document table. However, it would be nice to write LINQ queries that access tables prefixed with the collection name.
public class BigData
{
public int SomeNumber { get; set; }
public string SomeValue { get; set; }
}
public class BigDataIndex : MapIndex
{
public int SomeNumber { get; set; }
public string SomeValue { get; set; }
}
public class BigDataIndexProvider : IndexProvider<BigData>
{
public BigDataIndexProvider()
{
CollectionName = BigDataService.CollectionName;
}
public override void Describe(DescribeContext<BigData> context)
=> context.For<BigDataIndex>()
.Map(x => new()
{
SomeNumber = x.SomeNumber,
SomeValue = x.SomeValue
});
}
public class BigDataMigration : DataMigration
{
public int Create()
{
SchemaBuilder.CreateMapIndexTable<BigDataIndex>(table => table
.Column<int>(nameof(BigDataIndex.SomeNumber))
.Column<string>(nameof(BigDataIndex.SomeValue)),
collection: BigDataService.CollectionName
);
SchemaBuilder.AlterIndexTable<BigDataIndex>(table =>
{
table.CreateIndex("IDX_SBD_NUM", nameof(BigDataIndex.SomeNumber));
table.CreateIndex("IDX_SBD_VAL", nameof(BigDataIndex.SomeValue));
},
collection: BigDataService.CollectionName);
return 1;
}
}
public class BigDataService
{
private readonly ISession _session;
public const string CollectionName = "BIG_DATA";
public BigDataService(ISession session)
{
_session = session;
}
public async Task<IEnumerable<BigDataIndex>> GetDataAsync()
{
// This method throws ex: no such table: BigDataIndex
return await _session
.LinqQueryAsync(accessor => accessor
.GetTable<BigDataIndex>()
.ToListAsync());
}
}
public class BigDataController : Controller
{
private readonly BigDataService _bigDataService;
public BigDataController(BigDataService bigDataService)
{
_bigDataService = bigDataService;
}
public async Task<IActionResult> GetData()
{
var data = await _bigDataService.GetDataAsync();
return Ok(data);
}
}
public class Startup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.Configure<StoreCollectionOptions>(x => x.Collections.Add(BigDataService.CollectionName));
services.AddSingleton<IIndexProvider, BigDataIndexProvider>();
services.AddScoped<IDataMigration, BigDataMigration>();
services.AddScoped<BigDataService>();
}
}
from helpful-libraries.
I see, so basically the issue is that the methods in LinqToDbQueryExecutor
expect the table name to be the same as the class name, but your is BIG_DATA_BigDataIndex
, right?
We could fix this by adding a GetTable(string tableName)
to ITableAccessor
for the generic case, maybe a GetTable<T>(string collectionName)
shortcut as well.
from helpful-libraries.
That's right. Thank you!
from helpful-libraries.
Great then!
Looking at the types I mentioned, would you consider a contribution for this?
from helpful-libraries.
Yes (with another github account)
from helpful-libraries.
Thank you!
from helpful-libraries.
Related Issues (17)
- Add locking to CacheServiceMonitor HOT 2
- Create `InvokeAsync` extension methods for `Task` returning delegates
- Split the Orchard Core specific methods into its own project (OSOE-70) HOT 4
- Add missing docs to public methods and Markdown files (OSOE-153) HOT 4
- The existing field's DisplayName gets overwritten for no reason. (OSOE-474) HOT 7
- The collection being enumerated is modified inside the `foreach` loop. (OSOE-605)
- Make it possible to replace content items with an unknown ID using recipes (OSOE-648) HOT 3
- Updated for 1.10? HOT 5
- Relative URL prefixed with /Admin in case of an admin controller action if [Route] attribute is used (OSOE-653) HOT 4
- Retrive the Admin prefix from `AdminOptions.AdminUrlPrefix` instead of hardcoding it (OSOE-657) HOT 4
- Enable nullable reference types in the solution and evaluate code (OSOE-754) HOT 3
- LinqQueryAsync throwing connection error if we setup Persist Security Info=False in connection string. (OSOE-801) HOT 5
- Add source generator that reads a JSON value as a const string at compile time. (OSOE-819) HOT 10
- Use source generation to create the `public partial class Program` needed by UITT (OSOE-829)
- Does not work in Orchard 1.9.x HOT 1
- Linq2db queries should only use transactions for write queries (OSOE-343) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from helpful-libraries.