I am trying to generate a dynamic warranty end date by calculation and I am getting nowhere with intelisense. Any help will be appreciated.
public int WarrantyMonths {get;set;}
public DateTime DateIn{get;set;}
public DateTime? WarrantyEnd
{
get { return DateTime.AddMonths(this.DateIn((this.WarrantyMonths))); }
}
You should read the documentation on how to use a function if you don't understand it. What you probably want is:
get { return DateIn.AddMonths(WarrantyMonths); }
Related
wanted to call a stored procedure with oracle so after searching I found that
to do this I have to create a model and make context and of these things. but after doing that I got this out of nowhere
The required column was not present in the results of a 'FromSql' operation.
I'm working with asp core 2.2 and EF Core 2.2.1, now I'm getting these and I can't figure it out how to fix it or what is wrong .
I tried many things but nothing changes
Here are my files
Model
namespace test2._2.Models
{
public class CodeProc
{
public int ID { get; set; }
public int Erorrcode { get; set; }
public string ErrorMsg { get; set; }
}
}
Context
namespace test2._2.Models
{
public partial class ModelCodingContext : DbContext
{
public ModelCodingContext(DbContextOptions<ModelCodingContext> optionss)
: base(optionss)
{
}
public virtual DbSet<CodeProc> CodeProcs { get; set; }
}
}
the actual procedure to call and run and print the results
var result = await _dbCodingContext.CodeProcs.FromSql("begin FIX_CODING.GET_CLIENT_CODE12(245,255,:num1,:num2,:msg);end;", oracleParameter, oracleParameter2, oracleParameter3).ToArrayAsync();
ViewData["test"] += result.ToString();
Your required columns are: ID, Erorrcode, ErrorMsg
Check that the stored procedures returns exactly these columns. Account for case sensitivity, so 'ID' doesn't equal 'Id' as well as 'Errorcode' doesn't equal 'ErrorCode'.
Luckily, I solved my own by making the stored procedure to return a refcursor rather than 3 values and it went for good. but I wonder what to do if it returns values not a refcursor.
I'm having problems with ASP.NET Core MVC and decimal? value.
I have the following view model:
public class BlobViewModel
{
public int Id { get; set; }
public int? IntegerValue { get; set; }
public string StringValue { get; set; }
[DataType(DataType.Date)]
public DateTime? DateValue { get; set; }
public decimal? DecimalValue { get; set; }
}
And the following input element in my view
<input asp-for="DecimalValue" class="form-control" />
When I enter a decimal value, e.g. "68.5" or "68,5" and tab out of the input element, I get the following error:
The value '68.5' is not valid for DecimalValue.
I have tried with the [DataType(DataType.Currency)] attribute above the property, but I can't seem to get the binding to work. The other properties binds as expected.
Does anyone have an idea for how I accomplish this?
The error you get occurs if you local Windows settings isn't set to US localization and you are using the default asp.net template jquery validation to validate decimal values. The errors should occur irrespective if your decimals are nullable or not
In ASP.NET Core I don't think you can force the localization to US in the web.config as you get in this answer in the same way you can for ASP.NET MVC5 and earlier, so you will have to add javascript to override the jquery.validate.js as mentioned as an answer to the same question.
create a js file called validationlocalization and put it in your wwwroot\js folder with the following contents
$.validator.methods.range = function (value, element, param) {
var globalizedValue = value.replace(",", ".");
return this.optional(element) || (globalizedValue >= param[0] && globalizedValue <= param[1]);
}
$.validator.methods.number = function (value, element) {
return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:[\s\.,]\d{3})+)(?:[\.,]\d+)?$/.test(value);
}
In the cshtml pages that require decimal validation add a reference to the javascript file to your scripts section. Make sure it is added after an reference to the existing _ValidationScriptsPartial.
#section Scripts {
...
<script src="~/js/validationlocalization.js"></script>
More detail on this workaround
Objective: Use the model to show total sales of an id and total sales difference for multiple periods.
Issue: Using MVC4 I have a model for a report that displays total sales. I know I can add a variable for each additional period, but I have many periods that I'd like to use to compare and show a difference. How can this be done avoiding needless repetition?
public class Report
{
public long ID { get; set }
public long TotalSales { get; set}
public long TotalSales2 { get; set}
public long TotalSalesDiff { get; set}
}
Thank you in advance for any suggestions and/or comments
If I understood your scenario you have two option either create a dictionary that can create properties or use Dynamic object class
For dictionary
public class DictionaryProperty
{
Dictionary<string, object> Yourproperties = new Dictionary<string, object>( );
public object this[ string name ]
{
get
{
if ( Yourproperties.ContainsKey( name ) )
{
return Yourproperties[ name ];
}
return null;
}
set
{
Yourproperties[ name ] = value;
}
}
}
}
And for the Dynamic object please refer following link
http://msdn.microsoft.com/en-us/library/system.dynamic.dynamicobject.aspx
cheers
I don’t have enough points to add a comments that’s the why I make this is an answer.
i have to retrive some data and count of the rows based on the criteria
the bellow is my code snippet
criteria.SetProjection(Projections.ProjectionList().Add(Projections.Property("LastUpdatedUserName"),"OperatorName")
.Add(Projections.Property("Created"),"enrollmentdate")
.Add(Projections.Count("NIK"), "enrollmentcount")
.Add(Projections.GroupProperty("LastUpdatedUserName"))
.Add(Projections.GroupProperty("Created")))
.SetResultTransformer(NHibernate.Transform.Transformers.AliasToEntityMap);
var result = criteria.List<Demographic>()
and this snippet resulting in exception while running
here goes the exception
ex.message=Unable to perform find[SQL: SQL not available]
ex.innerexception={"The value \"System.Collections.Hashtable\" is not of type \"Indo.Id.Data.Infrastructure.Entities.Demographic\" and cannot be used in this generic collection.\r\nParameter name: value"}
and the stack trace is
at System.ThrowHelper.ThrowWrongValueTypeArgumentException(Object value, Type targetType)
at System.Collections.Generic.List1.VerifyValueType(Object value)
at System.Collections.Generic.List1.System.Collections.IList.Add(Object item)
at NHibernate.Util.ArrayHelper.AddAll(IList to, IList from) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Util\ArrayHelper.cs:line 233
at NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 1948
type casting of the transformation to demographic will work to max extent but here in demo graphics i have approx 40 columns and i have declared a new class for holding the result like
public class operatorenrollment
{
public string OperatorName { get; set; }
public DateTime enrollmentdate { get; set; }
public int enrollmentcount { get; set; }
}
can i now transform this to new class like
NHibernate.Transform.Transformers.AliasToBean(typeof(operatorenrollment))
any help here is very much appriciable
thanks in adv
The error is pretty clear.
You are using Transformers.AliasToEntityMap, which transforms your projection into an IDictionary, and trying to get back a list of Demographic.
Use Transformers.AliasToBean<Demographic>() instead.
I have a [DataContract] called ReportRequest with a
NOT NULL column 'SubmittedAt'. So my DataContract looks something like:
[DataContract]
public class ReportRequest
{
Int32 templateId;
DateTime submittedAt = DateTime.Now;
[DataMember]
public virtual Int32? Id
{
get;
set;
}
public virtual DateTime SubmittedAt
{
get {
return submittedAt;
}
set
{
submittedAt = value;
}
}
}
Because, I have taken a private variable submittedAt and is initialised with DateTime.Now,
shouldn't the SubmittedAt property have the same value??
But when i am calling NHibernate
session.Save(objReportRequest);
I am getting the error:
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
Any thoughts why I am getting this error?
As a workaround for now I have changed getter for SubmittedAt property as:
get {
if (submittedAt == DateTime.MinValue)
return DateTime.Now;
else
return submittedAt;
}
SQL Server minimum DateTime value is bigger than DateTime.Min value. So you cannot save minimum value to database.
As Marek Tihkan already said: SqlServer can not store the DateTime.MinValue, it is outside of the value range of SqlServer's DateTime data type.
The best advise is to use nullable types anyway:
[DataContract]
public class ReportRequest
{
DateTime? submittedAt = null;
public virtual DateTime? SubmittedAt
{
get {
return submittedAt;
}
set
{
submittedAt = value;
}
}
}
By SubmittedAt.HasValue you know if it is actually set to something reasonable. You shouldn't depend on some "magic values" to decide if a value is initialized or not.
It's because DateTime.MinValue doesn't have the same meaning as the minimum value you could store in a SQL Server datetime column. In SQL server datetime column the minimum date you could store is the one you get in your exception stack. It is SqlDateTime.MinValue