Advertisements

Entity Framework : Could not load type System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider

December 8, 2017 Leave a comment

When you have separate class library projects for Data access layer which contains your entity model and when you are giving reference of this class library to your web application on build you may get following error

Could not load type System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider

You can solve this error by following line assembly reference in your website project webconfig file

<system.web>
    <compilation debug="true" targetFramework="4.5">
        <assemblies>
            <add
                assembly="System.Data.Entity.Design, Version=4.0.0.0,Culture=neutral,
                PublicKeyToken=B77A5C561934E089" />
        </assemblies>
    </compilation> 
    <httpRuntime targetFramework="4.5" />
</system.web>

 

Advertisements

Microsoft.VisualStudio.Editor.Implementation.EditorPackage’ package did not load correctly: Visual Studio 2012

November 26, 2017 Leave a comment

The Problem

When starting Visual Studio …

  • … by loading a solution file, no windows display and the Solution Explorer remains empty.
  • … you get a bunch of error messages thrown in your face.
  • … you can only add text in the editor, not remove it.
  • … some other strange, unexplainable thing prevents you from using Visual Studio as you normally would.

TerminalServerIssue

 

The Solution

If you are having one of the issues above and neither restarting Visual Studio or rebooting your machine helps, then there is a large change your Component Model Cache is corrupt and you need to delete that folder using following steps

So, here is how you fix it:

  1. Close Visual Studio (if you haven’t done so already out of despair)
  2. Open a file explorer window and navigate to your AppData folder. You can get there by:
    1. In the search bar, type %APPDATA%/.. and press enter
    2. Alternatively, navigate to C:\Users\\AppData
  3. Go into Local\Microsoft\VisualStudio\<version> where <version> is 12.0 for Visual Studio 2013.
  4. Delete the ComponentModelCache folder.

Hope it helps !

 

Kendo grid error : kendo.all.min.js:12 Uncaught TypeError: e.slice is not a function

November 13, 2017 Leave a comment

Getting Uncaught TypeError: e.slice is not a function error message while binding kendo grid with data using controller action method

Following is the sample code for View and Controller action

View :

$(function () {
$(“#grid”).kendoGrid({
height: 400,
dataSource: {
serverPaging: true,
serverFiltering: true,
serverSorting: true,
pageSize: 10,
transport: {
read: “Employee/Read”,
contentType: “application/json”,
type: “POST”
},
},
schema: {
data: “Data”,
total: “Total”,
},

columns: [
{ field: “Salary”, format: “{0:c}”, width: “150px” },
{ field: “EmployeeName”, width: “150px” },
{ field: “SalaryColor”, width: “100px” },
{ command: “destroy”, title: “Delete”, width: “110px” }
],

editable: true, // enable editing
pageable: true,
sortable: true,
filterable: true,
toolbar: [“create”, “save”, “cancel”], // specify toolbar commands
parameterMap: function (options) {
return kendo.stringify(options);
}
});
});

Controller Read Action :

public ActionResult Read(int take, int skip, IEnumerable<Sort> sort, Kendo.DynamicLinq.Filter filter)
{
SalesERPDAL salesDal = new SalesERPDAL();

var result = salesDal.Employees.OrderBy(p => p.FirstName)
.Select(p => new EmployeeViewModel
{
EmployeeName = p.FirstName,
Salary = “5000”,
SalaryColor = “yellow”
}).ToDataSourceResult(take, skip, sort, filter);

return Json(result,JsonRequestBehavior.AllowGet);
}

Problem is in above code we are passing whole result instead of only Data part of result should be passed.

return Json(result.Data,JsonRequestBehavior.AllowGet);

Hope this help !

Categories: ASP.NET Tags: , , ,

AngularJS With Asp.net Web API: $http post returning XMLHttpRequest cannot load: Response for preflight has invalid HTTP status code 405

November 7, 2017 Leave a comment

When trying to POST json to Asp.net web api server using $http its returning the following error

Response for preflight has invalid HTTP status code 405

OR

MVC web api: No ‘Access-Control-Allow-Origin’ header is present on the requested resource

Following is the solution for above problem

Cors

I installed Cors in my project using nu-get command line

Install-Package Microsoft.AspNet.WebApi.Cors

and added the following code in WebApiConfig.cs file from App_Start folder.

var enableCorsAttribute = new EnableCorsAttribute("*",
                          "Origin, Content-Type, Accept",
                          "GET, PUT, POST, DELETE, OPTIONS");
config.EnableCors(enableCorsAttribute);

and removed the following from the web config

<remove name="X-Powered-By" />
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Accept, Content-Type, Origin" />
<add name="Access-Control-Allow-Methods" value="GET, PUT, POST, DELETE, OPTIONS" />

SQL : Paging in Stored Procedure

November 1, 2017 Leave a comment

Create simple Student table using following script

CREATE TABLE [dbo].[Student]( [ID] [int] NOT NULL, [Name] [varchar](50) NOT NULL) ON [PRIMARY]GO

The OFFSET-FETCH clause is used to fetch specif records. OFFSET-FETCH can be used only with the ORDER BY clause.

Stored Procedure :

SP

Limitations in Using OFFSET-FETCH

  • ORDER BY is mandatory to use OFFSET and FETCH clause.
  • OFFSET clause is mandatory with FETCH. You can never use, ORDER BY … FETCH.
  • TOP cannot be combined with OFFSET and FETCH in the same query expression.
  • The OFFSET/FETCH rowcount expression can be any arithmetic, constant, or parameter expression that will return an integer value. The rowcount expression does not support scalar sub-queries.
Categories: Sql Server Tags: , ,

EF code first – Model compatibility cannot be checked because the database does not contain model metadata

October 10, 2017 Leave a comment

This suggests that migration table is out of sync (even if your data isn’t), and that’s been part of the db schema now (since 4.3 I think – under system tables).

There could be many reasons and ways to experience that error , but most of the time…

The problematic part is some combination of manually backing/restoring the full database with code changes alongside – I’m not entirely certain as to why always.

In short, even if Db-s are the same migration table data might not be – and hash comparison may fail (still full restore sounds like good enough – but you have ‘two sides’).

What works for me is to use
Update-Database -Script

That creates a script with a ‘migration difference’,
which you can manually apply as an SQL script on the target server database (and you should get the right migration table rows inserted etc.).

If that still doesn’t work – you can still do two things…

a) remove the migration table (target – under system tables) – as per http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-automatic-migrations-walkthrough.aspx comments in there – that should fail back to previous behavior and if you’re certain that your Db-s are the same – it’s just going to ‘trust you’,

b) as a last resort I used – make a Update-Database -Script of the full schema (e.g. by initializing an empty db which should force a ‘full script’),
find the INSERT INTO [__MigrationHistory] records,
just run those, insert them into the database,
and make sure that your databases – and code match,

that should make things run in sync again.

(disclaimer: this is not a bullet proof to work at all times, you may need to try a few things given your local scenarios – but should get you in sync)

Also this will work

I found the code will work by changing

static LaundryShopContext()
{
Database.SetInitializer<LaundryShopContext>(
new DropCreateDatabaseIfModelChanges<LaundryShopContext>());
}
into

static LaundryShopContext()
{
Database.SetInitializer<LaundryShopContext>(
new DropCreateDatabaseAlways<LaundryShopContext>());
}

 

MYSQL : How to skip first 10 records from a SELECT query and take next 10?

October 4, 2017 Leave a comment

We know there are skip and take operators available in linq to skip and take

The Take operator is used to return a given number of rows from a object list and the Skip operator skips over a specified number of rows in object list.

var employee = (from emp in employeeContext.EMPLOYEEs

where emp.SALARY < 1300

select emp).Skip(2).Take(5);

Is there a way in MySQL to achieve the same like have the first 10 result from a SELECT query skipped and select next 10?

Answer : Yes we can use LIMIT with two parameter

Introduction to MySQL LIMIT clause

The LIMIT clause is used in the SELECT statement to constrain the number of rows in a result set. The LIMIT clause accepts one or two arguments. The values of both arguments must be zero or positive integers.

The following illustrates the LIMIT clause syntax with two arguments:

Let’s examine the LIMIT clause parameters:

  • The offset specifies the offset of the first row to return. The offset of the first row is 0, not 1.
  • The count specifies the maximum number of rows to return.

When you use the LIMIT clause with one argument, this argument will be used to determine the maximum number of rows to return from the beginning of the result set.

SELECT *  FROM table LIMIT count;

Use LIMIT with two parameters. For example, to return results 11-60 (where result 1 is the first row), use:

SELECT * FROM foo LIMIT 10, 50
Hope this help !