This project has moved and is read-only. For the latest updates, please go here.

CodeFirst with EDMX

Apr 11, 2013 at 3:06 PM
Edited Apr 11, 2013 at 3:11 PM
I used effort tool for unit testing and i used dbContext and followed your tutorial My code is shown in below
       IDataLoader loader = new Effort.DataLoaders.CsvDataLoader("Company.csv");
       DbConnection connection = Effort.DbConnectionFactory.CreateTransient(loader);
       InvoiceEntities context = new InvoiceEntities(connection);

       CompanyRep companyRep = new CompanyRep(context);
       var comList = companyRep.GetCompany();
Then i got this error
Code generated using the T4 templates for Database First and Model First development may not work correctly if used in Code First mode. To continue using Database First or Model First ensure that the Entity Framework connection string is specified in the config file of executing application. To use these classes, that were generated from Database First or Model First, with Code First add any additional configuration using attributes or the DbModelBuilder API and then remove the code that throws this exception.
Apr 11, 2013 at 3:50 PM
Edited Apr 12, 2013 at 9:28 AM
Hello,

I have deleted my previous response, because I figured out what is really going on.

It seems that your DbContext class is generated from an EDMX file. In this case you should use EntityConnectionFactory. It requires to pass an entity connection string that contains a reference to the complete scheme of your database.

I had no idea that EntityConnection can be used with DbContext before, so I will update the related tutorials.
Apr 11, 2013 at 6:14 PM
I used EntityConnectionFactory . This time i got a new error
Schema specified is not valid. Errors: 

(0,0) : error 0026: MaxLength '2147483647' is not valid. Length must be between '0' and '1073741823' for 'string' type.

(0,0) : error 0026: MaxLength '2147483647' is not valid. Length must be 
I used this code

            IDataLoader loader = new Effort.DataLoaders.CsvDataLoader("Company.csv");

            DbConnection connection = Effort.EntityConnectionFactory.CreateTransient("name=InvoiceEntities", loader);

            InvoiceEntities context = new InvoiceEntities(connection);


            CompanyRep companyRep = new CompanyRep(context);
            var j = companyRep.GetCompany();
Apr 11, 2013 at 10:12 PM
This bug has been already fixed, you can download and compile the most recent version of the library yourself until a new release is published.
Apr 12, 2013 at 8:34 AM
Thank you very much. Sorry for the inconvenience. I downloaded the newer version of effort then automatically fixed the previous error.
But i got a another new error . "The underlying provider failed" . More detail about the error i attached the screenshot

Image


Thanks,
Abi
Apr 12, 2013 at 9:24 AM
Edited Apr 12, 2013 at 9:33 AM
This seems to be a new one.

Might I ask you to show me more details of the exception (stack trace, inner)? Which version of EF are you using?
Apr 12, 2013 at 2:54 PM
Edited Apr 12, 2013 at 3:05 PM
I used EF 6. I attached my POC project Here
Apr 12, 2013 at 3:02 PM
Oh, sorry but EF6 is not fully supported yet.
Apr 12, 2013 at 3:46 PM
In my project first i used EF 4.1. That time i got an error
Error 2 Assembly 'Effort, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' which has a higher version than referenced assembly 'EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' D:\POC\UnitTestWithEffort\UnitTestWithEffort.Tests\bin\Effort.dll UnitTestWithEffort.Tests
so only i upgrade my EF version
Apr 12, 2013 at 3:53 PM
Try to compile Effort with the /Main/Build/Build.cmd script. It will create a zip package that contains multiple builds of Effort you can choose from.
Apr 12, 2013 at 5:15 PM
Edited Apr 12, 2013 at 5:19 PM
Hi.
I tried to many more ways to unittesting . All other tool are working good but your tool is very easy to achieve unittest
My Heartfelt thanks to you .
My code working good.
Image