Entity Framework Example



  • I have been using the .NET ConsoleApp example as a starting point. I figured I could write a console application that would create all of my reports from a database. I am new to the entity framework and learning C#.

    Is there an example using the Entity Framework?

    I started by creating a class for my report and a method 'CreateReport'. I have another class for the database context and a class in the models folder (ReportView.cs).

    A couple of questions:

    1. Do the templates have to be in the jsreport/data/templates/(ReportName) folder or can they be in a jsreport/templates folder? If so, is there a configuration file I need to update?

    2. Do I need to use the beforeRender method?

    3. How do I pass the DbSet into the RenderByNameAsync method.

    The function is below:
    ''' public bool CreateReport()
    {

            var db = new DBContext();
            if (db.Database.Exists() == false)
            {
                return false;
            }
    
            Console.WriteLine("Connected to {0}.\n", db.Database.Connection.Database);
            int ItemCount = db.ReportView.Count();
            Console.WriteLine("There are {0,7} entries in the View.", ItemCount.ToString("#,#", CultureInfo.InvariantCulture));
    
            Console.WriteLine("Initializing local jsreport.exe utility");
            var rs = new LocalReporting()
                .RunInDirectory(Path.Combine(Directory.GetCurrentDirectory(), "jsreport"))
                .KillRunningJsReportProcesses()
                .UseBinary(JsReportBinary.GetBinary())
                .Configure(cfg => cfg.AllowedLocalFilesAccess().FileSystemStore().BaseUrlAsWorkingDirectory())
                .AsUtility()
                .Create();
    
            Console.WriteLine("Rendering localy stored template jsreport/data/templates/ReportView into ReportView.pdf");
            var ViewReport = rs.RenderByNameAsync("ReportView", db.ReportView).Result;
            //ViewReport.Content.CopyTo(File.OpenWrite("ReportView.pdf"));
    
            return true;
        }
    

    '''

    Thanks.



  • I see that a request for an example was also made a month ago.


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.