.net

Entity Framework - Insert Related Entities

I'm trying to insert an entity (document) with the EF and ASP.NET. My entity model and schema is below, and I'm getting an unusual error about a foreign key mismatch on the Tutors table. Entities in 'SchoolEntities.Courses' participate in the 'FK_Courses_Tutors' relationship. 0 related 'Tutors' were found. 1 'Tutors' is expected. I'm...

How to get fields from such a string?

I'm importing some data from a database. The data has been stored by a CMS written in php where I have no control. Here is the data (a dense report from a paypal response): a:56:{ s:8:"business";s:19:"[email protected]"; s:14:"receiver_email";s:19:"[email protected]"; s:11:"receiver_id";s:13:"KVBRSDFJKLWYE"; s:9:"item_name";s:4:"ABC...

What is the name for this usage of delegate in C#?

This is a terminology question. In C#, I can do this: delegate Stream StreamOpenerDelegate(String name); void WorkMethod(StreamOpenerDelegate d) { // ... } void Exec1() { WorkMethod((x) => { return File.OpenRead(x); }); } void Exec2() { StreamOpenerDelegate opener = (x) => { ...

Set values with a Linq-Query ?

In my application I have a list of items I need to sort by price and set a rank/position index for each item. I need to store the rank because the price may change afterward. At the moment I am doing it like this: var sortedlistKFZ = from res in listKFZ orderby res.Price select res; if (sortedlistKFZ.Any()) { int rankPosition = 1; ...

What is the VB equivalent of this C# syntax, dealing with delegates?

Is it possible to translate the following C# code into VB.NET, using VB 9.0? delegate Stream StreamOpenerDelegate(String name); void Exec1() { WorkMethod( x => File.OpenRead(x)); } void Exec2() { StreamOpenerDelegate opener = x => return File.OpenRead(x) ; WorkMethod(opener); } Can I do something like this?: Private Del...

Using Websphere MQ with JMS from a .NET application.

I'm trying to send a message to a java server over a Websphere MQ which uses JMS as the transport protocol. I can happily drop messages on the MQ using the IBM supplied libraries, but the server rejects them. I'm assuming (hopefully correctly) that this is because I'm missing various JMS specific headers/properties on the MQ message. ...

Can a Func<> call itself recursively?

I was playing around with a code golf question yesterday for building a christmas tree which came around last year and I threw together a quick recursive algorithm to do the job: static string f(int n, int r) { return "\n".PadLeft(2 * r, '*').PadLeft(n + r) + (r < n ? f(n, ++r) : "*".PadLeft(n)); } I got to wondering if I ...

iPhone Application using Web Services

Hey im looking to developed some webservices for an Iphone, id like to do this in a .NET environment. Whats the best way to get started i.e. Can I just go ahead and create the webservices I need first off all like any other webservice or does there need to be some consideration since these webservice will be built for IPhone. Also my...

Wanted : List of data following certain rules concerning dates

Hi all, here is my problem. I have a list of data, sorted by dateStart : index dateStart dateEnd value [0] 2009-11-01 04:20 2009-11-01 05:40 5 [1] 2009-11-01 06:30 2009-11-01 08:42 10 [2] 2009-11-01 07:43 2009-11-01 16:12 0 [3] 2009-11-01 10:43 2009-11-01 14:34 -12 [4] 2...

How to Inject Open Connections with an IoC

First, my scenario. I have a service, BillingService, has a constructor like this: BillingService(IInstallmentService, IBillingRepository) The InstallmentService has a constructor that looks like this InstallmentService(IBillingRepository, IInstallmentCalculator) My Billing service is an application service and the methods will coor...

How can I overwrite file web.config with web.other.config?

I have a msbuild script with custom logic to deploy my service to the qa server automatically. I have to overwrite the default config with a dedicated one, but when I use <Copy SourceFiles="web.other.config" DestinationFiles="web.config" /> it does nothing. How can I make it work? ...

Why does this IF statement return false?

I have two text boxes and I want skip a block of code only when both are empty: if (txtBox1.Text.Trim() != string.Empty && txtBox2.Text.Trim() != string.Empty ) { // Do something } If either of the text boxes has something, I want the //Do something part to execute. Only when both are empty do I want to skip. However the above c...

ASP.Net Security By Route

I'm working with ASP.Net Dynamic Data and I have a section in my web.config like this: <location path="Foo/List.aspx"> <system.web> <authorization> <allow roles="The Name of Some Role"/> <deny users="*"/> </authorization> </system.web> </location> This works fine for restricting access to that path, however lat...

Issue with my button's code not being executed

I have an image button that when clicked the first time it just seems to submit the page like an old classic asp button. However, after the submit the button's code is executed. Any idea what can cause this? <asp:Button ID="bttnfinal" style="cursor:pointer;display:none" CausesValidation="false" OnClientClick="return true;" runat="serv...

Smart Software Installer - resume at last failure

Hello folks, Has anyone out there ever written your own software installer in .Net that has a "pickup at last failure" ability baked in? e.g. Let's say the install copies a bunch of files, registers some DLLs, sets up/manipulates a database (MS SQL), and sets up a data driven web site (IIS) that uses said database. If the database man...

Getting logical drives

I use following code to get logical drives: string[] strDrives = Environment.GetLogicalDrives(); but when I want to iterate through it, an exception occurs, with the message: Drive Not Ready How can I get just ready drives? ...

EntLib logging - add/edit TraceListeners at runtime

I have a web application where I would like to add or edit Enterprise Library logging at runtime. I'm familiar with how to configure EntLib Logging completely programmatically and through the config file, but I would like to use a combination of the two. I'd like to have some base TraceListeners setup via the config file, but then at a...

Lock before reading a global string?

I have class than spins off a backgroundworker to do some processor intensive stuff. The background worker reads a few strings that are declared globally for the whole class... do I need to lock around those strings? The backgroundworker never write the strings, they simply represent some directory locations that are set in the construct...

Streaming a big file directly to the database

I'm using a WCF application to save a file received via streaming to the database. I interact with my database using LINQ to SQL. I need a way to insert any data I receive automatically to the database. ...

How can I query NTFS disk quotas in C#?

I need to be able to find, for all users on a given remote machine, those users' disk quotas and actual disk usage. I need to be able to do this reporting in a C# application. (Well, technically a DLL plugin for an app I've already built; but that's irrelevant here.) The remote machine is not on the same network, however, the applicati...