1

I am currently trying to search and update a cross-reference table that has an extra "ranking" column, like so: | que_guid (Guid) | tag_guid (Guid) | ranking (long) |. The goal is to create a FAQ, so the point of this table is to link questions and tags together, while keeping track of a relevance score as ranking points stored in a long int.

The Question class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;


namespace FirstFaqTest.Models {
    public class Questions {
        public string que_guid { get; set; }

        public string que_ten_code { get; set; }
        public string que_question {get; set; }
    }
}

The Tag class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;


namespace FirstFaqTest.Models {
    public class Tags {
        public string tag_ten_code { get; set; }
        public string tag_guid { get; set; }
        public string tag_name { get; set; }
    }
}

The TagQuestion class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace FirstFaqTest.Models
{
    public class TagQuestions
    {
        public string tqu_tag_guid { get; set; }
        public string tqu_que_guid { get; set; }
        public long tqu_pertinence { get; set; } //ranking
    }
}

My problem is I have no idea how to update the ranking column.

I have already made it so the PK is composite using the modelBuilder in my Context class, like so:

protected override void OnModelCreating(ModelBuilder modelBuilder) {
    modelBuilder.Entity<Questions>()
                .HasKey(que => que.que_guid);
    modelBuilder.Entity<Tags>()
                .HasKey(tag => tag.tag_guid);
    modelBuilder.Entity<TagQuestions>()
                .HasKey(tqu => new { tqu.tqu_que_guid, tqu.tqu_tag_guid } );
}
1
  • @GertArnold Just did it.
    – kDjouzi
    Oct 10, 2018 at 8:05

2 Answers 2

0

Put the complex business logic of the database into a store procedure and then expose the needed variables to facilitate the operation to the consumer. Then in EF call the stored procedure as needed.

Note as of .Net Core 2, the framework for calling a stored procedure was not in place and one had to use ADO.Net call to make the call. It is unclear to me if this is the same situation; regardless you will be able to make the call from EF or from ado.net off of the EF credentials as needed.

0

In the end it was a quick, simple fix... Using 2 Where() clauses did the trick:

var tagQu = ctx.TagQuestions
               .Where(c => c.tqu_que_guid.Equals(tqu_que_guid))
               .Where(c => c.tqu_tag_guid.Equals(tqu_tag_guid))
               .FirstOrDefault();

This can work with FirstOrDefault() because I'm working with GUIDs and I've made both of those particular columns a composite primary key:

modelBuilder.Entity<TagQuestions>()
            .HasKey(tqu => new { tqu.tqu_que_guid, tqu.tqu_tag_guid });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.