Getting error on add new “Table ‘conjero.tmpidentity_project_consultant_order’ doesn’t exist” on MySql CodeFirst with EF

In my project I am handling two type auto generated keys. Long and Guid. Previously long only i used in this project. Now added Guid also. I previously used this with out any with out any problem in MSSQL. I created one table via migration. It works fine. In the case of second table, I created model and table separately for a reason.  At this time I getting an error while am try to add something.

Table ‘conjero.tmpidentity_project_consultant_order’ doesn’t exist

I don’t have any idea about tmpidentity_. What it is ?

Search in google about tmpidentity and got one link, https://github.com/pdonald/mysql-connector-net/blob/master/Source/MySql.Data.Entity/MySqlMigrationSqlGenerator.cs

Here talking about some TRIGGER. So I checked previously created table and its trigger. there is trigger for handling auto generated guid. I Just copy paste that trigger and rename as per second table name.

My issue fixed!!

Following is the trigger:

CREATE DEFINER=`root`@`%` TRIGGER `conjero`.`project_consultant_order_BEFORE_INSERT` BEFORE INSERT ON `project_consultant_order` FOR EACH ROW
BEGIN
DROP TEMPORARY TABLE IF EXISTS tmpIdentity_project_consultant_order;
		CREATE TEMPORARY TABLE tmpIdentity_project_consultant_order (guid CHAR(36))ENGINE=MEMORY;
		SET @var_Id = UUID();
		INSERT INTO tmpIdentity_project_consultant_order VALUES(@var_Id);
		SET new.Id = @var_Id;
END
Advertisements

The JSON request was too large to be deserialized.

I am working on a list and it has a bulk update through api. I am tested with upto 30 records and its working fine on my dev system. whilie update to QA they added a lot of records to update at that time I got an error The JSON request was too large to be deserialized

JSON request was too large
Problem is I am sending data as JSON as MVC’s default maximum Json deserializer members count is 1000. So I changed it in web.config.

<appSettings>
    <add key="aspnet:MaxJsonDeserializerMembers" value="150000" />
</appSettings>

kendoGrid cancel edit event

logo kendoui

My kendo grid need edit functionality for some specific rows. That is requirement. We can set editable column level
or grid level. I did’t find out an option for disable editable for rows.

I found two options for revert back to normal mode from edit mode.

$("#grid").data("kendoGrid").cancelChanges();
$("#grid").data("kendoGrid").closeCell();

I add a field in model for check is this row editable and check it on edit event.

$("#grid").kendoGrid({

			
			dataSource: GridSource,
			height: 450,
			sortable: true,
			resizable: true,			
			editable: true,
			pageable: true,
			dataBound: ongridDataBound,
			edit: function (e) {
				if (e.model.IsEditable == false) {
					e.sender.closeCell();
				}
			},
			columns: [...]

		});

Now disabled edit functionality for some rows is working fine.

User.Identity.Name is null

At this time I am set claims like following line.

identity.AddClaim(new Claim("UserName", context.UserName));

I changed this to


using (AuthRepository _repo = new AuthRepository())
{
  IdentityUser user = await _repo.FindUser(context.UserName, context.Password);

  if (user == null)
  {
     context.SetError("invalid_grant", "The user name or password is incorrect.");
     return;
  }
  ClaimsIdentity identity = new ClaimsIdentity(OAuthDefaults.AuthenticationType);
  identity.AddClaim(new Claim(ClaimTypes.Name, user.UserName));
  identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Id));
  context.Validated(identity);

}

IAppBuilder does not contain definition for UseWebApi

When I try to implement WebApi with owin, i got an error

IAppBuilder’ does not contain a definition for ‘UseWebApi’ and no extension method ‘UseWebApi’ accepting a first argument of type ‘IAppBuilder’ could be found (are you missing a using directive or an assembly reference?)

Solution is you need to install Microsoft ASP.NET Web API2 OWIN Self Host which will resolve the issue.

You can use the NuGet command Install-Package Microsoft.AspNet.WebApi.OwinSelfHost.
nuget_webapi_selfhost

DataTable to Dynamic List

format strings

Last day I got a requirement, it need a pivot table. I generated this table in SQL and read it to a datatable. No issues. Then I want convert this datatable to a list. I can’t create a entity because columns are dynamic. I stuck here some time and got a solution .

 

 

public static class HelperExtensions
{
  public static List<dynamic> ToDynamic(this DataTable dt)
  {
    var dynamicDt = new List<dynamic>();
    foreach (DataRow row in dt.Rows)
    {
      dynamic dyn = new ExpandoObject();
      dynamicDt.Add(dyn);
      foreach (DataColumn column in dt.Columns)
      {
         var dic = (IDictionary<string, object>)dyn;
         dic[column.ColumnName] = row[column];
      }
    }
    return dynamicDt;
  }
}