nullable

Hibernate / JPA -> Nullable values & objects?

谁都会走 提交于 2019-12-23 21:42:40
问题 My basic question is: How can I force Hibernate to make float NULLable and accept NULL for float, datetime, blob, respectively? I really mean NULL, not (float) 0.0. Even worse, when I try to store an object with the desired NULLable fields actually being NULL and using entity manager, I get errors for attributes, which are marked as NULLable by Hibernate even in the db table. Here is what I have been trying in vain: Consider this table: +--------+--------------+------+-----+---------+--------

My SQL table is set to allow NULL for this column, but when I run it, it says it cannot be NULL. What/Why/How?

本小妞迷上赌 提交于 2019-12-23 19:31:56
问题 so I have quite the odd predicament here. My SQL table is set to allow nulls for my ZipCode column, like so: CREATE TABLE [dbo].[Companies] ( [CompanyId] BIGINT IDENTITY(1,1) NOT NULL PRIMARY KEY, [Name] NVARCHAR(100) NOT NULL, [Address] NVARCHAR (100) NULL, [City] NVARCHAR (50) NOT NULL, [State] NVARCHAR (2) NOT NULL, [ZipCode] INT NULL, [PhoneNum] BIGINT NULL, [CreatedDate] DATETIME2 NOT NULL DEFAULT GetDate() ) This should let me have ZipCode's value as NULL, right? Well, apparently not...

How to Convert a Nullable DateTime variable's null value to DbNull.Value

允我心安 提交于 2019-12-23 17:12:26
问题 I have a nullable DateTime Variable. And I want to write it to SQL DB. When i try to insert: If the variable has value there is no problem. But if it hasn't a value, insertion interrupting with an error. I want to ask: How can we insert nullable DateTime to Sql via DbCommand Parameter? (P.S. : Sql column is nullable too.) DateTime? myDate = null; DbCommand dbCommand = new DbCommand(); dbCommand.Parameters.Add("NullableSqlDateField", DbType.DateTime, myDate); 回答1: Try the null coalescing

Nullable class?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 16:34:40
问题 I have this class public class FilterQuery { public FilterQuery() { } public string OrderBy { set; get; } public string OrderType { set; get; } public int? Page { set; get; } public int ResultNumber { set; get; } } I would like to use it like this public IQueryable<Listing> FindAll(FilterQuery? filterQuery) Is this possible? 回答1: This immediately begs the question of why . Classes are by definition reference types and thus are already nullable. It makes no sense to wrap them in a nullable

Is it possible to cheat C# compiler to box Nullable<T> struct ant not its value?

烂漫一生 提交于 2019-12-23 15:44:26
问题 Well, the question may seem odd. And it really is. Yet I strongly believe that such hacks help in understanding the language and .net platform. It is how C# compiler treats nullable types implies this question. Nullable<T> is a struct. But compiler boxes not this struct but the value it holds or just null reference. It is also intersting how unboxing will work in the case of the boxed Nullable. Nullable<int> myInt = boxedStruct as Nullable<int>; here I meen that boxedStruct is not a boxed int

Microsoft Likes the False value better?

淺唱寂寞╮ 提交于 2019-12-23 14:24:46
问题 Im reading Jon Skeet book. (#4) but one thing (among others) caught my eye : topic : bool? he wrote in a table that :(X,Y are bool?) X | Y | X & Y --------------------------- true null null ok fine... so the null is the one who decides. the bool operand here looses. X | Y | X & Y --------------------------- false null false why ? why the bool operand here is being taking into account while in the previous sample it was the null who decided about the result ...? It seems that true and false

What is a “DateTime?” as opposed to just a DateTime in C#? [duplicate]

馋奶兔 提交于 2019-12-23 12:59:18
问题 This question already has answers here : What does “DateTime?” mean in C#? (6 answers) Closed 6 years ago . What is the difference between a DateTime? and a DateTime (without a question mark) in C#? 回答1: DateTime? can be null as opposed to DateTime 回答2: A question mark after a value type is a shorthand notation for the Nullable<T> structure. Represents an object whose underlying type is a value type that can also be assigned null like a reference type. The Nullable<T> structure allows you to

How CLR can bypass throwing error when assigning a null value to the struct?

别等时光非礼了梦想. 提交于 2019-12-23 11:44:08
问题 I am trying to understand one thing in this code: Nullable<Int32> x = 5; Nullable<Int32> y = null; Console.WriteLine("x: HasValue={0}, Value={1}", x.HasValue, x.Value); Console.WriteLine("y: HasValue={0}, Value={1}", y.HasValue, y.GetValueOrDefault()); And Output is: x: HasValue=True, Value=5 y: HasValue=False, Value=0 And the thing that I don't understand when you pass null to y , I believe it calls public static implicit operator Nullable<T>(T value) but the definition of this method

Fluent NHibernate mapping nullable enum

时光总嘲笑我的痴心妄想 提交于 2019-12-23 09:33:06
问题 I need to map a nullable enum in my class but am getting exceptions. NHibernate.PropertyAccessException: Invalid Cast (check your mapping for property type mismatches); setter of App.Model.Stock ---> System.InvalidCastException: Specified cast is not valid. I have narrowed the issue down to one specific property, which I describe below. This was previously answered here, but the solution links to a page which no longer exists. Here is my code, which I have reduced to contain only the portions

Mark method call that it always returns not null result

 ̄綄美尐妖づ 提交于 2019-12-23 09:31:53
问题 Scala compiler has -Xcheck-null which tries to check if there are any potential null pointer dereference in runtime. It's ok for me, but I get too much false positives, i.e. suppose I define logger : private final val LOGGER: Logger = LoggerFactory.getLogger(classOf[GenericRestImpl]) The method getLogger never returns null . How can I pass this knowledge to compiler so it will not complain? [WARNING] TestImpl.scala:31: warning: potential null pointer dereference: LOGGER.debug [WARNING] LOGGER