.net

Updating a Detached Entity Instance using Entity Framework 4.0

I am utilizing Entity Framework 4.0 and WCF. I am new to using Entity Framework and am more familiar with NHibernate. However, I am concerned about detached instances of objects when performing an update. I have looked on various websites where they retrieve an object, attach the instance to their context, and set all properties to be ...

How to write this in LINQ

I have 3 tables in my database Group [GroupId, GroupName] GroupUser [GroupId, AuthorId] Author [AuthorId, AuthorName] Book [BookId, AuthorId, BookName] How do I grab a list of books for a particular GroupId? I have tried this LINQ statement: DataLoadOptions dlo = new DataLoadOptions(); dlo.LoadWith<GroupUser>(p => p.User); dlo.LoadW...

Visual Studio .NET unit test problem

When I run the Release build of my (VS 2008 .NET) unit tests, I get the following exception: System.IO.FileLoadException: Could not load file or assembly 'arcVegaORM, Version=1.0.3856.24327, Culture=neutral, PublicKeyToken=0dd85ae1d99ddbee' or one of its dependencies. The located assembly's manifest definition does not match the assemb...

How can I determine the "bit-ness" under which my C# application runs?

A .NET dll can be run as both 32 bit and 64 bit on a machine with an x64 processor. I need to determine at runtime what bitness my application is running under. Currently I've been doing something like System.IntPtr.Size == 8, but that seems like an ugly hack. Is there a more "correct" way of determining this? ...

Serialize Deserialize to/from xlsx

Given the following assemblage of classes (contrived): public class School { [PrimaryKey] public string Name {get; set;} [Set] public IList<Teacher> Teachers {get; set;} public class Teacher { [PrimaryKey] public string Name {get; set;} I'd like to have the object hierarchy serialized into a single sheet of an xlsx file, ...

nHibernate List mapping without key column?

I have the following entities. class Parent { public virtual int ID {get; set;} public virtual string Key {get; set;} public virtual string Type {get; set;} public virtual string Value {get; set;} public virtual IList<Child> Children {get; set;} } class Child { public virtual int ID {get; set;} public virtual string Paren...

Automapper for Java

Is there Java equivalent of .Net's Automapper? ...

JustMock vs. TypeMock vs. Other

With Telerik's JustMock product newly available, it has a lot of similarities to TypeMock, in the ability to mock concrete classes, not just abstract classes or interfaces. I was just curious your opinion on one or both of the products. What do you like or dislike? Seems like JustMock might be shy on some of the features (TypeMock has...

Can one copy the contents of one object to another dynamically if they have the same interface?

For example, if I have two objects, one which is of type Monkey and the other of type Dog, and they both implement IAnimal, which is something like this: interface IAnimal { int numberOfEyes {get; set;} string name {get; set;} } I want to do something like this: Monkey monkey = new Monkey() { numberOfEyes = 7, name = "Henry" }; D...

How to implement ISerializable in F#

Let's say you start off with this stub: [<Serializable>] type Bounderizer = val mutable _boundRect : Rectangle new (boundRect : Rectangle) = { _boundRect = boundRect ; } new () = { _boundRect = Rectangle(0, 0, 1, 1); } new (info:SerializationInfo, context:StreamingContext) = { // to do } interface ISerializable with member...

CUDA - Maintain pointers to global memory

I have a .NET program that is utilizing CUDA. The CUDA is accessed through a C DLL. What I am doing is initializing my CUDA application by allocating buffers (cudaMalloc) on the device at program startup. Pointers to these buffers are then maintained in static variables declared in the DLL. Data is copied to and from the buffers thro...

Really tough one... Windows Service throws System.BadImageFormatException on server 2008, x64, .net 4 migrated from 3.5

I'm really hoping someone's seen this before, because I'm dying on this one. I have tried compiling the service exe as AnyCPU, x86, and x64 It works on my win 7 x64 box I'm installing with installutil, the .net 4 version When I start the service, I get an error. It says nothing, but does point to which modules are loaded. Those of ...

Laptop/Desktop Sleep Events

I was wondering if there was an event that is triggered when a laptop or desktop goes into sleep mode. An example would be: When a user is working on his/her laptop and he/she flips the monitor down, the laptop goes into sleep mode. Or when a user goes to Start → Shutdown → Sleep. Are there any events built into .NET that determine t...

Problem accessing AppSettings via configSource in Windows Server 2003

According to the MSDN documentation, configSource is supported on Windows Server 2003 SP2. However, when I try to access a setting using the following syntax: System.Configuration.ConfigurationManager.AppSettings["SettingName"]; then null is returned. However, the same app works properly on Windows 7 and Windows XP (i.e. AppSettings["...

How to get Current Logged on UserName and Password??

Hi, I need Current Logged on User and Password , I can get UserName by using WindowsIdentity but not sure how to get Password ...

Elegant handling of a Collection Change that requires changes on the dispatcher thread.

Here's my situation: I've got a User interface ItemsControl "ResultsPresenter" (WPF) pulling from a ListCollectionView that uses a BindingList "Results" from a non-UserInterface class as the ListCollectionView.Source property. Whenever I make a change to "Results" such as an add operation, I get a NotSupportedException, insisting tha...

Serialize a .net Object directly to a NetworkStream using Json.net

Hello Is there any way to have Json.net serialize an object directly to a NetworkStream? In other words, have Json.net send the serialized result to the network as it serializes the object (in a streaming fashion). I would like to avoid having to serialize the object to memory and then send it via the NetworkStream. Any thoughts? Re...

Can I cause the NUnit GUI to break into the Visual Studio debugger on a breakpoint/failed test?

When using the NUnit GUI to run unit tests, is there a way to either: Set breakpoints inside the tests, or break into the Visual Studio Just-in-Time debugger upon failure of a test? ...

Getting list of groups a user belongs to from a windows service.

What is the best way to retrieve a list of groups a user belongs to from a windows service? List<string> groups = new List<string>(); foreach (IdentityReference ir in new WindowsIdentity(name).Groups) { SecurityIdentifier sid = new SecurityIdentifier(ir.Value); NTAccount ntAccount = (NTAccount)sid.Translate(typeof(NTAccount))...

USB drive programming with .NET

I am working on a project where I need to access some specific addresses of a USB drive (e.g. sector 0), and change some bytes. I have done some parts with C# already that includes user interface, detection of USB drives etc. Can anybody help me providing some links so that I can access specific addresses of USB drives with .NET? ...