.net

How to retrieve indentity column vaule after insert using LINQ

Could any of you please show me how to complete the following tasks? // Prepare object to be saved // Note that MasterTable has MasterTableId as a Primary Key and it is an indentity column MasterTable masterTable = new MasterTable(); masterTable.Column1 = "Column 1 Value"; masterTable.Column2 = 111; // Instantiate DataContext DataCont...

How can I make a type safe bag of items that all implement a generic interface?

Need to have a type-safe bag of items that all implement a generic interface. The desire is to do something like: var stringItem = new IItem<string>(); var numberItem = new IItem<int>(); var items = new List<IItem<T>>(); //T of course doesn't accomplish what I want items.Add(stringItem); items.Add(numberItem); Something like: inter...

Needed: File system interfaces and implementation in .NET

I write unit tests to my code, using Moq as a mocking framework. My code includes calls to the file system, using direct calls to System.IO classes. For instance, File.Exists(...) etc. I'd like to change that code to be more testable, so I should have an interface, say IFile, with a relevant method, say Exists(string path). I know I can ...

How to resize and save a Texture2D in XNA?

In a level editor I've made for my XNA game (editor is also in XNA) I'm allowing to scale Texture2D objects. When the user tries to save the level, I'd like to actually resize the image file on disk so that it doesn't require scaling in the game. Is there an easy way to create an image file (PNG preferred) from a scaled Texture2D objec...

Is it possible to use .NET assemblies In Access 2003?

Is it possible? If it is possible, how do I do it and is it problematic? ...

.NET Stopwatch Class limitations

This may not be an entirely not a .NET related question. I am writing a .NET application to control some gadgets. I send commands to the gadget periodically (say every 500 milliseconds). As soon as I send the command I start a timer. (.NET stopwatch class) If the gadget not respond within say, 10 milliseconds, I send the command again. ...

What is the LINQ to objects 'where' clause doing behind the scenes?

I've just replaced this piece of code: foreach( var source in m_sources ) { if( !source.IsExhausted ) { .... } } with this one: foreach( var source in m_sources.Where( src => !src.IsExhausted ) ) { ... } Now the code looks better (to me) but I'm wondering what's really happening here. I'm concerned about perf...

Data-driven state machine application

We are currently working on a "data-driven" state machine application. Right now, the state flows are all configured in the database, but none of the decision/business logic is configurable in the DB with our current design. Because of this, the code has to basically "know" the state flow as well, so there's really no point in configur...

Determine if a file can be moved or copied

Besides trying the operation and catching the exception, is there a method to determine if a file can be moved or copied? ...

Any slick and clever ways to inject JQuery before the page begins rendering?

I'm looking to somehow get jQuery inserted into every page with the MINIMUM of code written... in other words I don't want to write <script language="javascript" src="PATH TO JQUERY"></script> on every single aspx page. So far I've thought of using a Base class and inserting a "Response.Write" into the "page load" event. Besides that, w...

Should I use two "where" clauses or "&&" in my LINQ query?

When writing a LINQ query with multiple "and" conditions, should I write a single where clause containing && or multiple where clauses, one for each conditon? static void Main(string[] args) { var ints = new List<int>(Enumerable.Range(-10, 20)); var positiveEvensA = from i in ints where (i > 0) && ((i %...

LINQ to Entities Parameters in Generated Queries

I'm trying to create an expression to be used by the Where method of a LINQ to Entities query. Effectively: query.Where(farm => farm.PartyId == id); (id is an int) The code I'm using is: private struct Parameter<T> { public T Value; public Parameter(T value) { Value = value; } } Parameter<int> idParameter...

.NET 2.0 nullable types and database null musings

If .NET 2.0 nullable types was there from version 1, will DBNull.Value not be needed in the first place? Or RDBMS's null has no bearing with .NET's null? That is DBNull.Value will still be needed anyhow, regardless of .NET version 1 already have nullable types. ...

How to capture a video of my desktop with .NET?

Hello all, I would like to know if there is any way to capture a to capture a video (screencast) of my desktop with .NET? I am not looking for a screencast software, but simply a technique that would allow me to generate myself a video of my desktop. I thought of taking multiple screenshots, but I am not sure of how I could generate pr...

How to find empty port to start WCF web ServiceHost

How can I determine an un-used port to start a WCF ServiceHost to host a localhost web server on? I'm currently starting my service up statically on http://localhost:XXXX where XXXX is a static value in my code. I'd like to replace the XXXX with a GetUnusedPort() call... Any thoughts? ...

Tools to use to find suppressed exceptions?

I work on a fairly complex Open Source project (opensimulator.org). It's currently sitting around 300 KLOC of C#, and there are a number of places where code has built up to trap and ignore exceptions, which end up disguising subtle bugs. I'm wondering what tools are out there that can produce reports of overly general exception catchin...

Problems Decompressing a GZip Archive in .Net

I grabbed the following code somewhere off the net, and I am using it to decompress Gzip files, such as http://wwwmaster.postgresql.org/download/mirrors-ftp/pgadmin3/release/v1.8.4/src/pgadmin3-1.8.4.tar.gz but when I run It, I get an exception, stating that the magic number doesnt match. public byte[] Download(string pUrl) { WebClien...

Memory usage + .net

Is there a way in .net 2005 ide to find out the memory usage by variables inside a function and when their memory is made free by garbage collector. ...

What's wrong with my url encoding?

In my asp.net mvc application I created the following link: http://localhost:2689/en/Formula.mvc/351702++LYS+GRONN+5G+9%252f2++fds I get error 400 (bad request). I think it blocks at the %25 (forward slash). What am I doing wrong? --EDIT 3-- I tried not encoding anything at all but rather rely on the default encoding of Url.Rou...

How do I shutdown the computer?

How to shutdown my computer using C#? ...