X Tutup
Skip to content

Unrelated tables join and query #491

@santhidhanuskodi23

Description

@santhidhanuskodi23

I want abilty to query 2 tables like sql join, Those2 tables wont have any relationshp in the table. I have generated models cs files and dbcontext.cs file using EF command automatically.

SELECT C.CCode, C.CName, P.PCode, P.PName
FROM Client C
INNER JOIN Product P ON C.MCode = P.MCode AND C.CCode = P.CCode....

I have this code in startup.cs
public void ConfigureServices(IServiceCollection services)
{
try
{

            // Register IHttpContextAccessor
            services.AddHttpContextAccessor();

            // Register DBContext with IHttpContextAccessor
            services.AddDbContext<DBContext>((serviceProvider, options) =>
            {
                var httpContextAccessor = serviceProvider.GetRequiredService<IHttpContextAccessor>();
                var connection = new SqlConnection(GetConnectionString(httpContextAccessor));

                // var creds = new Azure.Identity.DefaultAzureCredential();
                // var token = creds.GetToken(new Azure.Core.TokenRequestContext(new[] { "https://database.windows.net/.default" }));
                // connection.AccessToken = token.Token;

                options.UseSqlServer(connection);
            });

            int DefaultPageSize = Configuration.GetValue<int>("DefaultPageSize");
            int MaxPages = Configuration.GetValue<int>("MaxPages");

            services.AddGraphQLSchema<DBContext>(provider =>
            {
                provider.OnFieldCreated = (field) =>
                {
                    if (field.ReturnType.IsList && field.ReturnType.SchemaType.GqlType == GqlTypes.QueryObject && !field.FromType.IsInterface)
                    {
                        field.UseFilter().UseSort().UseOffsetPaging(defaultPageSize: DefaultPageSize, maxPageSize: MaxPages);
                    }
                };
            });...

..............
.........
}.....
how and where I make these 2 tables related? what files would require changes? Client.cs, product.cs or dbcontext.cs or startup.cs?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup