Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

not able to retrieve values from SQL DB

$
0
0

I am trying to get values from my DB but I am unable to do so. I have created A model, context, A table is in SQL server and then started coding. My context is: 

 public partial class rsbsrdbContext : DbContext
    {        
        public rsbsrdbContext()
        {
        }
        public rsbsrdbContext(DbContextOptions<rsbsrdbContext> options)
            : base(options)
        {
        }
public virtual DbSet<RsbfileDetail> RsbfileDetails { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder.UseSqlServer("Server=link.amazonaws.com;User Id=admin;Password=pwd;Database=rsbsrdb;");
            }
        }

My model is:

public partial class RsbfileDetail
    {
        public string FileUrl { get; set; }
        public string Filename { get; set; }
        public string CaseId { get; set; }
        public string FileType { get; set; }
        public int FileReferenceId { get; set; }
        public DateTime? CreatedDate { get; set; }
        public DateTime? UpdatedDate { get; set; }
        public string Status { get; set; }
        public string FileId { get; set; }
        public string Preset { get; set; }
        public string TranscodeCallbackUrl { get; set; }
        public string FileTranscodeJobId { get; set; }
        public string TranscriptionCallbackUrl { get; set; }
        public string JobDefinition { get; set; }
        public string TranscriptionJobId { get; set; }
    }

Now, my code is:

class FilePickerService
    {
        private static readonly rsbsrdbContext _dbContext;
        private static string path = string.Empty;
        private static string authUrl = string.Empty;
        private static string url = string.Empty;
        private static string DownloadFileUri = string.Empty;
        public FilePickerService(IConfiguration config, rsbsrdbContext dbContext)
        {
            //_dbContext = dbContext;
            path = config["FilePath:SharedFolderPath"];
            authUrl = config["ApiUrls:authUrl"];
            url = config["ApiUrls:url"];
            DownloadFileUri = config["ApiUrls:DownloadFileUri"];
        }
        public async static void AiAuthenticate()
        {
            HttpClient client = new HttpClient();
            string authPath = authUrl + "/oauth/token";
            var parameters = new Dictionary<string, string> { { "username", "user" }, { "grant_type", "password" }, { "password", "password" } };
            var encodedContent = new FormUrlEncodedContent(parameters);
            var response = await client.PostAsync(authPath, encodedContent);
            string result = response.Content.ReadAsStringAsync().Result;
            var Bearer = result;            
        }
        public static void GetNewFileFromFolderToDB()
        {
            List<RsbfileDetail> result1 = new List<RsbfileDetail>(); result1=_dbContext.RsbfileDetails.Where(j => (j.Filename == "sample.txt")).ToList();
            Console.WriteLine(result1);
        }

The highlighted line returns error: "object reference not set to an instance of an object." I did not  understand what I did wrong. Please help me with this.


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>