Couchbase new field not getting inserted - c#

So initially my class is as follows...
public class ClientTransaction
{
public decimal ClientBalance { get; set; }
public DateTime ClientTransactionDate { get; set; }
public int ClientTransactionTypeId { get; set; }
public string ClientTransactionTypeName { get; set; }
public decimal TransactionAmount { get; set; }
public decimal TaxRate { get; set; }
}
All fields are saved into couchbase.
Then i change the class to add a new field called Description.
public class ClientTransaction
{
public decimal ClientBalance { get; set; }
public DateTime ClientTransactionDate { get; set; }
public int ClientTransactionTypeId { get; set; }
public string ClientTransactionTypeName { get; set; }
public decimal TransactionAmount { get; set; }
public decimal TaxRate { get; set; }
public string Description { get; set; }
}
I populate the description field and do an upsertAsync but the description field is not in the database even though the upsert was a success.
Please advise.

Related

Display two table data in one

Hi doing a master details and currently in the process of display two tables data based on invoice number but I have this error
An exception of type 'System.Data.Entity.Core.EntityCommandExecutionException' occurred in EntityFramework.SqlServer.dll but was not handled in user code
{"Invalid column name 'klsm_Invoice_InternalInvoiceNo'.\r\nInvalid column name 'klsm_Invoice_InternalInvoiceNo'.\r\nInvalid column name 'klsm_Invoice_InternalInvoiceNo'."}
I am following Tutorial: Implement CRUD Functionality with the Entity Framework in ASP.NET MVC but I have come to a problem.
Desc class
[Table("klsm_InvoiceDesc")]
public class Desc
{
[Key]
public string InternalInvoiceNo { get; set; }
public string InvoiceNo { get; set; }
public int DescNo { get; set; }
public string Principal { get; set; }
public string ChargeCode { get; set; }
public string Quantity { get; set; }
public string Description { get; set; }
public string UnitPrice { get; set; }
public string Amount { get; set; }
public string ForeignAmount { get; set; }
public string EL1 { get; set; }
public string EL2 { get; set; }
public string ShortName { get; set; }
public string InvoiceType { get; set; }
public string PONumber { get; set; }
public string Batch { get; set; }
public string CCVBatch { get; set; }
public string PaidAmount { get; set; }
public string Paid { get; set; }
public string TT { get; set; }
public string BankCode { get; set; }
//public string Id { get; set; }
public virtual College klsm_Invoice{ get; set; }
}
College class
[Table("klsm_Invoice")]
public class College
{
[Key]
public string InternalInvoiceNo { get; set; }
public string InvoiceNo { get; set; }
public DateTime InvoiceDate { get; set; }
public string CustomerName { get; set; }
public int Year { get; set; }
public int Month { get; set; }
public decimal Amount { get; set; }
public decimal ForeignAmount { get; set; }
public string UserCreated { get; set; }
public string UserModified { get; set; }
public int AccMonth { get; set; }
public int AccYear { get; set; }
public string AccStatus { get; set; }
public string Status { get; set; }
public string PaidStatus { get; set; }
public string Principal { get; set; }
public DateTime DateCreated { get; set; }
public DateTime DateModified { get; set; }
public string EL1 { get; set; }
public string InvoiceType { get; set; }
public string CurrencyType { get; set; }
public decimal ExchangeRate { get; set; }
public string GSTChecked { get; set; }
public DateTime PaymentSchedule { get; set; }
public string PaymentMode { get; set; }
public string CashAdvance { get; set; }
public virtual ICollection<Desc> klsm_InvoiceDesc { get; set; }
}
Home Controller
public ActionResult Details(string id)
{
College klsm_Invoice = db.klsm_Invoice.Find(id);
return View(klsm_Invoice);
}

NewtonSoft JSON Deserialization: System.StackOverflowException

The JSON deserialization is failing with the exception System.StackOverflowException.
I'm trying the deserialize the following entity. Need help, why this is causing the issue.
var workingJSONString = "{\"FBTOrLeaseYear\":{\"DateFrom\":\"2019-03-02T00:00:00\",\"DateTo\":\"2020-03-01T00:00:00\"},\"Registration\":\"155SQN\",\"NovatedLeaseFortnightBenefitGroups\":[],\"NovatedLeaseAnnualBenefitGroups\":[]}";
var exceptionJSONString = "{\"FBTOrLeaseYear\":{\"DateFrom\":\"2019-03-02T00:00:00\",\"DateTo\":\"2020-03-01T00:00:00\"},\"Registration\":\"155SQN\",\"NovatedLeaseFortnightBenefitGroups\":[{\"BenefitGroupID\":1,\"BenefitGroupName\":\"Fuel\",\"TotalAnnualBudgetAmount\":4992.0000,\"TotalFortnightBudgetAmount\":192.0000,\"TotalSpentToDate\":3327.43,\"TotalFortnightSpent\":141.59276595744680851063829788,\"TotalProjAnnualAmount\":3681.4119148936170212765957447,\"TotalVariationAmount\":1310.5880851063829787234042553,\"AverageSpentPercentage\":14.645499465811966666666666667,\"NovatedLeaseBudgetSpentDataForBenefits\":[]}],\"NovatedLeaseAnnualBenefitGroups\":[]}";
Test.Entities.NovatedLeaseBenefitsBudgetSpentFBTYear novatedLeaseBenefitsBudgetSpentFBTYearResponse = new Test.Entities.NovatedLeaseBenefitsBudgetSpentFBTYear();
novatedLeaseBenefitsBudgetSpentFBTYearResponse = JsonConvert.DeserializeObject<Test.Entities.NovatedLeaseBenefitsBudgetSpentFBTYear>(exceptionJSONString); // Exception is thrown here
Entities:
On deserialization of the "Test.Entities.NovatedLeaseBenefitsBudgetSpentFBTYear" entity,
I'm getting an exception "System.StackOverflowException". Can one please help me why the deserizarion is failing for this JSON.
public class NovatedLeaseBenefitsBudgetSpentFBTYear
{
public FBTOrLeaseYear FBTOrLeaseYear { get; set; }
public string Registration { get; set; }
public List<NovatedLeaseBenefitGroup> NovatedLeaseFortnightBenefitGroups { get; set; }
public List<NovatedLeaseBenefitGroup> NovatedLeaseAnnualBenefitGroups { get; set; }
}
public class NovatedLeaseBenefitGroup
{
public int BenefitGroupID { get; set; }
public string BenefitGroupName { get; set; }
public double TotalAnnualBudgetAmount { get; set; }
public double TotalFortnightBudgetAmount { get; set; }
public double TotalSpentToDate { get; set; }
public double TotalFortnightSpent { get; set; }
public double TotalProjAnnualAmount { get; set; }
public double TotalVariationAmount { get; set; }
public double AverageSpentPercentage { get; set; }
public List<NovatedLeaseBudgetSpentDataForBenefit> NovatedLeaseBudgetSpentDataForBenefits { get; set; }
}
public class NovatedLeaseBudgetSpentDataForBenefit
{
public int BenefitId { get; set; }
public string BenefitName { get; set; }
public double AnnualBudgetAmount { get; set; }
public double FortnightBudgetAmount { get; set; }
public double SpentToDate { get; set; }
public double FortnightSpent { get; set; }
public double ProjAnnualAmount { get; set; }
public double VariationAmount { get; set; }
public double SpentPercentage { get; set; }
}
public class FBTOrLeaseYear
{
public string DateFrom { get; set; }
public string DateTo { get; set; }
}

How To Assign the value in OneModel to AnotherModel

How to Assign the value in one model to another model without using AutoMapper ,foreach,and instance and then it will access any way to send value in one model to another model its is possible and then my source model will be byte array ..
This is my source model...
public class OneDriveItem : OneDriveItemBase
{
public string Id { get; set; }
public string Name { get; set; }
public string ETag { get; set; }
public OneDriveIdentitySet CreatedBy { get; set; }
public DateTimeOffset CreatedDateTime { get; set; }
public OneDriveIdentitySet LastModifiedBy { get; set; }
public DateTimeOffset LastModifiedDateTime { get; set; }
public long Size { get; set; }
public string WebUrl { get; set; }
public OneDriveItem[] Children { get; set; }
public OneDriveRemoteItem RemoteItem{ get; set; }
}
This is my Target Model
public class OneDriveModels
{
public string Id { get; set; }
public string Etag { get; set; }
public string Name { get; set; }
public string WebUrl { get; set; }
public string CTag { get; set; }
public long Size { get; set; }
public DateTime CreatedDateTime { get; set; }
public DateTime LastModifiedDateTime { get; set; }
public string DownloadUrlAnnotation { get; set; }
}
You can decide not to look for a shortcut and do it with a constructor/factory method.
For example:
public class OneDriveModels
{
public static FromOneDriveItem( OneDriveItem source)
{
Id = source.Id
ETag = source.ETag
(...)
}

Not getting object data from Json deserialization

I am getting Json data from a web server, but when I try to deserialize it to objects, I am not getting any data. The Json string looks like this:
{"success":true,"data":[{"Id":6,"CustomerGuid":"70b390d8-82d5-4bba-aa68-fc8268a1b1ff","UserName":"victoria_victoria#nopCommerce.com","Email":"victoria_victoria#nopCommerce.com","CustomerRoles":[{"Id":3,"Name":"Registered","SystemName":"Registered"}],"AdminComment":null,"IsTaxExempt":false,"AffiliateId":0,"VendorId":0,"HasShoppingCartItems":false,"Active":false,"Deleted":false,"IsSystemAccount":false,"SystemName":null,"LastIpAddress":null,"CreatedOnUtc":"\/Date(1472933472393)\/","LastLoginDateUtc":null,"LastActivityDateUtc":"\/Date(1472933472393)\/","ExternalAuthenticationRecords":[],"ShoppingCartItems":[]},{"Id":5,"CustomerGuid":"eb9e6f24-f362-4c10-942a-366e2919dc11","UserName":"brenda_lindgren#nopCommerce.com","Email":"brenda_lindgren#nopCommerce.com","CustomerRoles":[{"Id":3,"Name":"Registered","SystemName":"Registered"}],"AdminComment":null,"IsTaxExempt":false,"AffiliateId":0,"VendorId":0,"HasShoppingCartItems":false,"Active":false,"Deleted":false,"IsSystemAccount":false,"SystemName":null,"LastIpAddress":null,"CreatedOnUtc":"\/Date(1472933472363)\/","LastLoginDateUtc":null,"LastActivityDateUtc":"\/Date(1472933472363)\/","ExternalAuthenticationRecords":[],"ShoppingCartItems":[]},{"Id":4,"CustomerGuid":"9f46dbae-6942-410c-90b8-9b38a0890064","UserName":"james_pan#nopCommerce.com","Email":"james_pan#nopCommerce.com","CustomerRoles":[{"Id":3,"Name":"Registered","SystemName":"Registered"}],"AdminComment":null,"IsTaxExempt":false,"AffiliateId":0,"VendorId":0,"HasShoppingCartItems":false,"Active":false,"Deleted":false,"IsSystemAccount":false,"SystemName":null,"LastIpAddress":null,"CreatedOnUtc":"\/Date(1472933472317)\/","LastLoginDateUtc":null,"LastActivityDateUtc":"\/Date(1472933472317)\/","ExternalAuthenticationRecords":[],"ShoppingCartItems":[]},{"Id":3,"CustomerGuid":"6277386b-13ee-427b-9cfe-4ebfa487c340","UserName":"arthur_holmes#nopCommerce.com","Email":"arthur_holmes#nopCommerce.com","CustomerRoles":[{"Id":3,"Name":"Registered","SystemName":"Registered"}],"AdminComment":null,"IsTaxExempt":false,"AffiliateId":0,"VendorId":0,"HasShoppingCartItems":false,"Active":false,"Deleted":false,"IsSystemAccount":false,"SystemName":null,"LastIpAddress":null,"CreatedOnUtc":"\/Date(1472933472253)\/","LastLoginDateUtc":null,"LastActivityDateUtc":"\/Date(1472933472253)\/","ExternalAuthenticationRecords":[],"ShoppingCartItems":[]},{"Id":2,"CustomerGuid":"241f45f1-b38c-4e22-8c5a-743fa3276620","UserName":"steve_gates#nopCommerce.com","Email":"steve_gates#nopCommerce.com","CustomerRoles":[{"Id":3,"Name":"Registered","SystemName":"Registered"}],"AdminComment":null,"IsTaxExempt":false,"AffiliateId":0,"VendorId":0,"HasShoppingCartItems":false,"Active":false,"Deleted":false,"IsSystemAccount":false,"SystemName":null,"LastIpAddress":null,"CreatedOnUtc":"\/Date(1472933472207)\/","LastLoginDateUtc":null,"LastActivityDateUtc":"\/Date(1472933472207)\/","ExternalAuthenticationRecords":[],"ShoppingCartItems":[]},{"Id":1,"CustomerGuid":"a940dc03-5f52-47d2-9391-8597b3b31cf2","UserName":"tony#lakesideos.com","Email":"tony#lakesideos.com","CustomerRoles":[{"Id":1,"Name":"Administrators","SystemName":"Administrators"},{"Id":2,"Name":"Forum Moderators","SystemName":"ForumModerators"},{"Id":3,"Name":"Registered","SystemName":"Registered"}],"AdminComment":null,"IsTaxExempt":false,"AffiliateId":0,"VendorId":0,"HasShoppingCartItems":true,"Active":true,"Deleted":false,"IsSystemAccount":false,"SystemName":null,"LastIpAddress":"71.185.255.7","CreatedOnUtc":"\/Date(1472933470783)\/","LastLoginDateUtc":"\/Date(1477522483903)\/","LastActivityDateUtc":"\/Date(1477523996553)\/","ExternalAuthenticationRecords":[],"ShoppingCartItems":[{"Id":1,"StoreId":1,"ShoppingCartTypeId":1,"CustomerId":1,"ProductId":18,"AttributesXml":null,"CustomerEnteredPrice":0.0000,"Quantity":1,"CreatedOnUtc":"\/Date(1473801903447)\/","UpdatedOnUtc":"\/Date(1473803336207)\/","IsFreeShipping":false,"IsShipEnabled":true,"AdditionalShippingCharge":0.0000,"IsTaxExempt":false}]}]}
I created these classes from the recommendation given in this link:
recommendation
I used this to create the classes: json2csharp
Response class:
class Response
{
bool success;
IList<Customer> data;
}
Customer class:
class Customer
{
public int Id { get; set; }
public string CustomerGuid { get; set; }
public string UserName { get; set; }
public string Email { get; set; }
public List<CustomerRole> CustomerRoles { get; set; }
public object AdminComment { get; set; }
public bool IsTaxExempt { get; set; }
public int AffiliateId { get; set; }
public int VendorId { get; set; }
public bool HasShoppingCartItems { get; set; }
public bool Active { get; set; }
public bool Deleted { get; set; }
public bool IsSystemAccount { get; set; }
public object SystemName { get; set; }
public string LastIpAddress { get; set; }
public DateTime CreatedOnUtc { get; set; }
public DateTime? LastLoginDateUtc { get; set; }
public DateTime LastActivityDateUtc { get; set; }
public List<object> ExternalAuthenticationRecords { get; set; }
public List<object> ShoppingCartItems { get; set; }
}
CustomerRole class:
class CustomerRole
{
public int Id { get; set; }
public string Name { get; set; }
public string SystemName { get; set; }
}
ExternalAuthenticationRecord class:
class ExternalAuthenticationRecord
{
public int Id { get; set; }
public int CustomerId { get; set; }
public string Email { get; set; }
public object ExternalIdentifier { get; set; }
public object ExternalDisplayIdentifier { get; set; }
public object OAuthToken { get; set; }
public object OAuthAccessToken { get; set; }
public string ProviderSystemName { get; set; }
}
ShoppingCartItem class:
class ShoppingCartItem
{
public int Id { get; set; }
public int StoreId { get; set; }
public int ShoppingCartTypeId { get; set; }
public int CustomerId { get; set; }
public int ProductId { get; set; }
public object AttributesXml { get; set; }
public double CustomerEnteredPrice { get; set; }
public int Quantity { get; set; }
public DateTime CreatedOnUtc { get; set; }
public DateTime UpdatedOnUtc { get; set; }
public bool IsFreeShipping { get; set; }
public bool IsShipEnabled { get; set; }
public double AdditionalShippingCharge { get; set; }
public bool IsTaxExempt { get; set; }
}
I am using this statement to deserialzie the Json string: Response res = (Response)JsonConvert.DeserializeObject(customerJson, (typeof(Response)));
When I stop it in the debugger, it shows "res" as data: null and success: false.
I am not getting any errors. It is just not giving me the data from the Json string.
Any help that anybody can provide to figure out why I'm not getting the data I want in "res", would be gratefully appreciated.
Thanks,
Tony
The problem is related to the accessibility level in your Response class. By default the fields, property and method are private so JsonConvert is not able to fill the properties.
Change the class as follow:
class Response
{
public bool success {get; set;}
public IList<Customer> data {get; set;}
}
And it wil works.
Another improvement is related to the JsonConvert use. To avoid the explicit cast use this type conversion: JsonConvert.DeserializeObject<T>(string) where T will be Response

String or binary data would be truncated.The statement has been terminated while removing data

I have a PriceId and I get some PriceGaranties by it and I am trying to delete PriceGaranties by updating Price and see this error.
Here is the code:
public void DeletePriceGaranties(int priceId)
{
var deletedPriceGaranties = context.PriceGaranties.Where(p => p.PriceId == priceId).ToList();
foreach (var priceGaranty in deletedPriceGaranties)
{
context.PriceGaranties.Remove(priceGaranty);
context.SaveChanges();
}
}
The error is:
String or binary data would be truncated. The statement has been
terminated.
Update
Here are the models:
public class Price
{
public int PriceId { get; set; }
public int ProductId { get; set; }
public int ClassId { get; set; }
public int ClassPartnerId { get; set; }
public int UserId { get; set; }
public decimal Cost { get; set; }
public string Url { get; set; }
public string Description { get; set; }
public DateTime LastUpdate { get; set; }
public bool Enable { get; set; }
public int CostTypeId { get; set; }
public int Value { get; set; }
public Class Class { get; set; }
public Product Product { get; set; }
public User User { get; set; }
public List<OldPrice> OldPrices { get; set; }
public List<PriceColor> PriceColors { get; set; }
public List<PriceGaranty> PriceGaranties { get; set; }
public ClassPartner ClassPartner { get; set; }
}
public class PriceGaranty
{
public int PriceGarantyId { get; set; }
public int PriceId { get; set; }
public int GarantyId { get; set; }
public Comparing.Model.Price.Price Price { get; set; }
}
And all of string types are nvarchar(MAX).
You have specified the length of the string in your database to be shorter than what you are trying to add to it. E.g. you may have set a varchar length in your database to be of length 10 but the string you want to add is 11, 15, 20 etc characters. The database doesnt know what to do with it so it just cuts off the excess characters. Try setting the field length in your database to a larger length.

Categories