Thanks Gary. I actually wrote a generic method that I thought would take care of the casting issue, but now I'm getting an "unable to convert from type Object to type Long." I've posted it as a separate question because I'm probably not understanding what syntax to use.
Note that the generic method resolved the first problem I was having, which is that it was returning DBNull in situations for non-nullable types. I understand that the DB field is returned as an object and I understand that the object returned is not going to be implicitly converted to the C# types.
What I can't understand is the syntax I need to use in the generic method. I suspect it's the <t> part because that's where I'm getting "Unable to cast type Object to type long" exceptions
///<summary>/// Converts DB types to C# Types and ensures that DBNull gets converted to the default value for the type.
///</summary>///<typeparamname="T">The expected return type</typeparam>///<paramname="value">The value of a column, straight form the database provider</param>///<returns>The value as its coorisponding C# Type, with DBNull converted to the default value of the type. </returns>public T DBToType<T> ( T value )
if ( !Convert.IsDBNull ( value ) )
return ( T ) Convert.ChangeType ( value , typeof ( T ) );
returndefault ( T ); //returns the default for the type... not null
You only need the async modifier if you've got an await in the method. All this method needs to do is return a Task or some kind, which your method isn't doing. A dirty conversion of your code to returning a Task would be:
public Task<CompanyEntity> GetCompany(int id)
return Task.Factory.StartNew<CompanyEntity>(() =>
using (var db = new JayhawkDB())
CompanyEntity results = null;
var query = from x in db.Companies
where x.Id == id
var record = query.FirstOrDefault<Company>();
results = new CompanyEntity
Id = record.Id,
CreatedById = record.CreatedById,
CreatedDT = record.CreatedDt,
DeletedById = record.DeletedById.GetValueOrDefault(),
DeletedDT = record.DeletedDt.GetValueOrDefault(),
CompanyName = record.CompanyName,
Abbreviation = record.Abbreviation,
Notes = record.Notes
The caller awaits this code, not the other way around.
Oh, and that try/catch block is pretty much useless if all you're going to do is catch all Exceptions and just re-throw them.
System.ItDidntWorkException: Something didn't work as expected.
This works, sort of. However, it does not give me the raw input from the keyboard so when AltGr is pressed it canges from Key.RightAlt => Key.LeftCtrl + Key.RightAlt whitch is Windows interpretation according to this: AltGr key - Wikipedia[^]. I dont want this, as I want the user to be able to "bind" any key to a spesific action.
That could work, but I also want it to react to a sequence of inputs like Visual Studio does. For instance, if you have selected parts of the code you can hold LeftCtrl + K, release the keys and press LeftCtrl + F, VS will format the code for you. Then KeyBoard.IsDown is not really usable.
The problem is that I need to know what happened on your keyboard before windows do changes to it.
I'd have to say this smells badly of spam - it's a limited trial of a paid-for app, and you've been here long enough to know that is the kind of thing that attracts "spam" and "spammer" votes and gets your account closed. Particularly when it's a "special promo" for CodeProject as the link implies.
I don't think spam was your intention, but I'd strongly suggest that you remove the link before it gets reported in S&A and you get kicked out.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
In Visual C#, I made a user control, which contains several separate "individual" properties. But I would like to make it into one. In which there is a plus sign in font of my property where users could click on it and expand it and access its members. Just like the property Location, Size, or Font.
I tried packaging all those properties into one class and use the class as the property type, but then I have no idea how to get or set the values! And the property just return the whole class as the value! There is NO plus sign for anybody to click!
PLEASE help me out! Thank you very VERY much! God bless you!!!
To create a Property like this you must create a Class-Object which holds the necessary Sub-Properties.
This Object should also use as TypeConverter the ExpandableObjectConverter.
Now you can use this Class-Object as Type for your Property.