GithubHelp home page GithubHelp logo

Comments (7)

Piedone avatar Piedone commented on June 12, 2024

Can you explain what would you like to achieve, with an example?

from helpful-libraries.

intellimedhu avatar intellimedhu commented on June 12, 2024

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.

Piedone avatar Piedone commented on June 12, 2024

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.

intellimedhu avatar intellimedhu commented on June 12, 2024

That's right. Thank you!

from helpful-libraries.

Piedone avatar Piedone commented on June 12, 2024

Great then!

Looking at the types I mentioned, would you consider a contribution for this?

from helpful-libraries.

intellimedhu avatar intellimedhu commented on June 12, 2024

Yes (with another github account)

from helpful-libraries.

Piedone avatar Piedone commented on June 12, 2024

Thank you!

from helpful-libraries.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.