nullable

Generating Entity Framework based on Views: Nullable types

半腔热情 提交于 2020-01-07 04:30:27
问题 Some of the properties in a class generated by EF are nullable, and some arent. My first instinct was that this should be driven by Nullable property returned by sp_help MyView. But that doesn't seem to be the case. Some of my types that are returned as Nullable by sp_help get generated as Nullable , while others, get generated as just bool instead of Nullable*bool* what is it driven by, and is there any way to control it by the view? as a test i created ViewA and than ViewB which selected

Convert between nullable int and int

若如初见. 提交于 2020-01-05 10:26:10
问题 I would like to do something like this : int? l = lc.HasValue ? (int)lc.Value : null; where lc is a nullable enumeration type, say EMyEnumeration?. So I want to test if lc has a value, so if then give its int value to l, otherwise l is null. But when I do this, C# complains that 'Error type of conditional expression cannot be determined as there is no implicit conversion between 'int' and ''. How can I make it correct? Thanks in advance!! 回答1: You have to cast null as well: int? l = lc

Is there a shorthand for addition assignment operator for nullables that sets the value if null?

假装没事ソ 提交于 2020-01-05 04:28:30
问题 I am using nullable doubles to store the sum of some values pulled from various sources. The sum could be any real value or null if no elements are present. Currently, I use a null check and either assign or increment: double? sum = null; ... if(sum == null) sum = someTempValue; else sum += someTempValue; I know c# has several shorthand null checks for method calls and the such. My question is if there is a shorthand notation to the addition assignment operator += when using nullables that

How to set entity framework 4.5 to never set any property as Nullable

▼魔方 西西 提交于 2020-01-05 03:31:41
问题 The one feature that I cannot stand with-in the Entity framework is where the complex Result object sets some properties as Nullable. Is there a global setting to where that Nullable property is never set to yes? 回答1: It appears that even if you get the property Nullable to be False , that it will still generate a Nullable version of your object. Check out the accepted answer of Entity Framework: Set nullable to false, but type is still nullable. Also, read How to manually update your Entity

Null (?) Operator returns incorrect value when using generic type constructor. VB.NET

依然范特西╮ 提交于 2020-01-04 15:11:34
问题 I am experiencing some weird behavior when using Generic Types and null operator. Why does obj2.CurrentDate return a date value that appears to be incorrect when using the ? (short hand). If I long hand the null operator (if) in the property then it returns the correct and expected value. I thought the ? was the equivalent to the if(expression, returnIfTrue, returnIfFalse). Also, if the generic type constructor is removed, then the null operator works as expected. Why is this? Return If

Null (?) Operator returns incorrect value when using generic type constructor. VB.NET

廉价感情. 提交于 2020-01-04 15:11:14
问题 I am experiencing some weird behavior when using Generic Types and null operator. Why does obj2.CurrentDate return a date value that appears to be incorrect when using the ? (short hand). If I long hand the null operator (if) in the property then it returns the correct and expected value. I thought the ? was the equivalent to the if(expression, returnIfTrue, returnIfFalse). Also, if the generic type constructor is removed, then the null operator works as expected. Why is this? Return If

Unity Doesnt Serialize int? field

狂风中的少年 提交于 2020-01-04 09:37:12
问题 I have a class i want to change the properties of in the editor. So i made my class System.Serializable and made the variables public that i want to be able to change. Like so: [System.Serializable] public class UIOptionsRing { public float Radius, DistanceBetweenPoints, StartOffset, GapInDegrees; public int? GapAfterElementNumer = 3; //this var doesnt show up public Vector3 CircleCenter; public GameObject CircleElementsContainer; } But the problem i am having is that the GapAfterElementNumer

VB.NET: How do I use coalesce with db column values and nullable types? Or is there a better solution?

时光怂恿深爱的人放手 提交于 2020-01-04 06:00:38
问题 I'm trying to do something similar to what's described here, but with nullable types. http://www.csharp-station.com/Tutorials/Lesson23.aspx int availableUnits = unitsInStock ?? 0; In VB, it would be this: Dim availableUnits As Int32 = If(unitsInStock, 0) However I'm working with db columns, which could be DbNull, and nullable types, which can be Nothing (which is different to DbNull). If a column is DbNull, I want to return Nothing, otherwise return the value. For eg: Dim availableUnits As

SQL CLR Function to return nullable boolean

て烟熏妆下的殇ゞ 提交于 2020-01-03 18:58:21
问题 I'm trying to write a SQLCLR function that will return a nullable boolean value. If I declare the function like this: public static SqlBoolean? IsTimeZoneDST(SqlString timeZone) then I get an error when attempting to use the assembly saying the types for the return value do not match. Is there something I am missing or is it not possible to return a nullable boolean in this instance? 回答1: All of the .NET Sql* types have a .Null field (static property) that creates a new instance of what will

sql server bulk insert nulls into time column

蓝咒 提交于 2020-01-03 09:23:42
问题 I'm having trouble inserting null value from a bulk insert statement. Two columns are nullable and the Id is identity. The int nullable workd out fine, but the time doesn't. Here the bulk statement: BULK INSERT Circulation FROM '.....file.cs' WITH ( FIRSTROW = 2, MAXERRORS = 0, FIELDTERMINATOR = ',', ROWTERMINATOR = '', KEEPNULLS) Here is an extract of the csv: ID, IDStopLine, IDException, Hour, PositionHour, Day ,28, 8, 12:20, 52, 0 ,29, 163, , 1, Meaning that I'm trying to insert nulls in