0

I have to use for the first time the LinqToDB library, so I'm reading their step by step:

https://linq2db.github.io/articles/get-started/full-dotnet/existing-db.html

Which basically is:

     1-Create a new Project (Done, console one ) 
     2-Install the LinqToDB packages (Done, linq2db.SqlServer installed) 
     3-Generate model from database ( Done, with .tt file) 
     4-Use my model... 

Here starts the problem, firstly you have to add a .config file, my entire file looks like this:

<configuration>
<connectionStrings>
    <add name="MyDatabase" providerName="System.Data.SqlClient"
         connectionString="Server=DESKTOP-HMRUEF4\SQLSERVER;Database=CrudWF;Trusted_Connection=True;" />
</connectionStrings>

I just changed the connectionString to my local database string

Then it's already supposed to work in the main method ...

        static void Main(string[] args)
    {
        using (var database = new DataModels.CrudWFDB())
        {
            var q = from student in database.Alunos  
                    select student;

            foreach (var student in q)
                Console.WriteLine(student.Nome);
        }
    }

The Problem: When I run the app, in the line where new DataModels.CrudWFDB() is called it throws an exception:

LinqToDB.LinqToDBException: 'Configuration string is not provided.'

I didn't edit the autogenerated model class because I think the problem isn't there, but here is the constructor for CrudWFDB():

    public CrudWFDB()
    {
        InitDataContext();
        InitMappingSchema();
    }

I'm stuck on this part, what can I do?

Dale K
  • 25,246
  • 15
  • 42
  • 71
  • Is that your *entire* config file? If so, you're missing the closing tag `` and the `` tag. If your XML is malformed it won't load anything. – Corey Aug 10 '22 at 03:36
  • Fact, that was the first mistake I made, but even with the correct xml file it didn't work. Soon I'll show how I solved this problem, thank you for your answer anyways ^^ – Matheus de Oliveira Aug 27 '22 at 17:14

0 Answers0