'System.Linq.IQueryable<Microsoft.AspNet.Identity.EntityFramework.IdentityUser>' does not contain a definition for 'FirstOrDefaultAsync'

by sunil ravulapalli /18. December 2013 08:40 /entityframework /Comments (0)

If you get the following error

'System.Linq.IQueryable<Microsoft.AspNet.Identity.EntityFramework.IdentityUser>' does not contain a definition for 'FirstOrDefaultAsync' and no extension method 'FirstOrDefaultAsync'
accepting a first argument of type 'System.Linq.IQueryable<Microsoft.AspNet.Identity.EntityFramework.IdentityUser>' could be found (are you missing a using directive or an assembly reference?) 

For some reason visual studio is not able to help in adding the reference automatically using "Ctrl +." shortcut. You need to add in the following namespace to get this to work.

using System.Data.Entity;

 

System.InvalidOperationException: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'.

by sunil ravulapalli /12. November 2013 09:17 /entityframework /Comments (0)

I got this error when using Entity framework 6.0 from my MSTest project:

System.InvalidOperationException: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

To fix this put

var _temp = System.Data.Entity.SqlServer.SqlProviderServices.Instance;

anywhere in your test project. I put it in a constructor.

Reference:

http://entityframework.codeplex.com/workitem/1590

Call store procedure which does not return anything using Entity Framework

by sunil ravulapalli /10. May 2013 18:29 /entityframework /Comments (0)

This is the technique I am using currently, doesn't feel correct but works.

Main EF function

public int ExecWithStoreProcedure(string query, params object[] parameters)
{ 
   var _context = new CompanyDbContext();
   var ints = _context.Database.SqlQuery(query, parameters).ToList(); 
   return ints[0]; 
}

Caller function

public long InsertEmployee(string empName, decimal empSalary) 
{ 
   var lineIdParam = new SqlParameter("lineid", SqlDbType.BigInt) { Direction = ParameterDirection.Output, Size = 8 }; 
     var effectiveDateParam =  new SqlParameter("effectiveDate", SqlDbType.DateTime)  { Direction = ParameterDirection.Output, Size = 8 }; 

   ExecWithStoreProcedure("spInsertStuff @name, @salary, @lineid OUT, @effectiveDate OUT", 
                                      new SqlParameter("name", SqlDbType.Varchar)   { Value = empName }, 
                                      new SqlParameter("salary", SqlDbType.Decimal) { Value = empSalary}, 
                                      lineIdParam, 
                                      effectiveDateParam); 
   return lineIdParam.Value; 
}