vendredi 14 août 2015

Ef6 dot notation; Join on colums with condition like ,not equals

I am trying to join two tables based on column ID on Table2 to be like column ID on Table1

me.dbSet.Join(me.context.Table2, p => p.ID, e => e.ID, 
(p, e) => new { p, e }).Where(z => z.e.ID== uid)

the sql output :

 SELECT 
    1 AS [C1]  
    FROM  [NG].[T1] AS [Extent1]
    INNER JOIN [NG].[T2] AS [Extent2] ON [Extent1].[ID] = [Extent2].[ID] 
    WHERE [Extent2].[ID] = 'f520f7b3-215d-4dfe-9787-1eb6864fb335'

The sql i am trying to write with linq :

 SELECT 
    1 AS [C1]  
    FROM  [NG].[T1] AS [Extent1]
    INNER JOIN [NG].[T2] AS [Extent2] ON [Extent1].[ID] Like [Extent2].[ID] + '%'
    WHERE [Extent2].[ID] = 'f520f7b3-215d-4dfe-9787-1eb6864fb335'



via Chebli Mohamed

Re-usable C# test code that waits for IO

I'm experimenting with using async/await on WCF exposed methods/services. Everything works fine but I'd like to simulate the service method actually waiting for IO so that the service call will be registered with an IO completion port, and the thread put back into the thread pool.

To clarify, I'm just experimenting to confirm usage of IO completion ports and to get a better understanding of the mechanics of what's actually going on.

So e.g. my test service currently looks like this:

[ServiceContract]
public interface IHelloWorldService
{
    [OperationContract]
    string SayHello(string firstName, string lastName);


    [OperationContract]
    Task<string> SayHello2(string firstName, string lastName);
}


public class HelloWorldService : IHelloWorldService
{
    public string SayHello(string firstName, string lastName)
    {
        return string.Format("Hello {0} {1}", firstName, lastName);
    }

    public async Task<string> SayHello2(string firstName, string lastName)
    {
        string str = string.Format("Hello {0} {1}", firstName, lastName);
        return await Task.Factory.StartNew(() => str);
    }
}

I'd like to do something in SayHello2() to cause that code to wait for some IO, ideally a code pattern I can copy/paste to use in generally when I want to simulate waiting for IO.

Typically Thread.Sleep() is used to simulate a long running task, but I'm pretty sure that will put the thread pool thread to sleep and not trigger usage of an IO completion port .



via Chebli Mohamed

use using to dispose or resources

I am just starting to use "using" to make sure resources are disposed regardless of what happens.

Below is an example of some code that I have written to retrieve some data. My question is are all the "using" required or would it be enough to just have the first one?

        SomeMethod()
        {
            using (SqlConnection cn = new SqlConnection("myConnection"))
            {
                cn.Open();

                using (SqlCommand cmd = cn.CreateCommand())
                {
                    cmd.CommandText = "myQuery";
                    using (SqlDataReader rdr = cmd.ExecuteReader())
                    {
                        if(rdr.HasRows)
                        {
                            while (rdr.Read())
                                // do something
                        }
                    }
                }
            }
        }



via Chebli Mohamed

Set type of a variable using a condition

How to set type of a variable using a condition?
If I do like example below, my variable x is no more existing after the end if, here is my problem.

    If RequestedType = "Integer" Then
        Dim x As Integer
    Else
        Dim x As String
    End If



via Chebli Mohamed

Windows 10 requires .NET 3.5 on demand

I'm executing my .NET application in a clean Windows 10. As far as I know, it has installed .NET Framkework 4.0 or 4.5 by default.

My application is compiled with .NET 4.0. When I execute it, windows shows up a popup saying that I need to install .NET 3.5.

enter image description here

Do you know why? Maybe I have dependencies to .NET 2.0. What you suggest to do?



via Chebli Mohamed

Microsoft Edge: Get Window URL and Title

Previously I was using ShellWindows() API for IE to get the window Title and URL for my application Now with new development, Microsoft Edge is new and has many features under development.

I want to know how I can get the URL and Title of all the pages opened in MS-Edge. As none of the shell APIs are working with MS-Edge. I tried also with UI Automation but it does not return all the UI elements

I am using MS Visual Studio 2010 for development. Do I need new version of Visual Studio? Can anybody help me about how to access the Title and URL? Or Does MS-Edge not allow such an access due to security? thanks



via Chebli Mohamed

Can "legacy" .NET projects also use the new NuGet 3 features?

The new NuGet version fixes lots of problems (e.g. transitive dependency capabilities, dependency resolution at build time, single packages repository cache, etc.).

However I could only test it with the ASP.NET vNext and UWP projects.

Will these new features also be available for "legacy" projects (e.g. full .NET 4.5/4.6 projects, WPF, etc.)?



via Chebli Mohamed