我似乎缺少一些关于皇宫.对我,它看起来像它采取的一些要素SQL,我喜欢的少和移入C#语言,并利用他们的其他东西。

我的意思是,我可以看到的利益使用SQL-像陈述的事情上比其他数据库。但是,如果我想写SQL,那么,为什么不只是写SQL和保持它的C#?我是什么丢在这里?

有帮助吗?

解决方案

皇宫不是关于SQL。皇宫是关于被应用编程功能paradigmns上对象。

皇宫SQL是一个奥姆建在它上面的皇宫的基础,但皇宫得多。我不使用皇宫SQL,但我使用皇宫所有的时间。

采取的任务,寻找交的两名单:

前皇宫,这个任务需要编写一套foreach循环访问的小名单一旦为每一个项目,在大不列O(N*M),和需要大约10行的代码。

foreach (int number in list1)
{
    foreach (int number2 in list2)
    {
        if (number2 == number)
        {
            returnList.add(number2);
        }
    }
}

使用皇宫,也不一样的东西在一个线上的代码:

var results = list1.Intersect(list2);

你会注意到,看起来不像皇宫的,但它是。你不需要使用的表达法,如果你不想要。

其他提示

之前:

// Init Movie
m_ImageArray = new Image[K_NB_IMAGE];

Stream l_ImageStream = null;
Bitmap l_Bitmap = null;

// get a reference to the current assembly
Assembly l_Assembly = Assembly.GetExecutingAssembly();

// get a list of resource names from the manifest
string[] l_ResourceName = l_Assembly.GetManifestResourceNames();

foreach (string l_Str in l_ResourceName)
{
    if (l_Str.EndsWith(".png"))
    {
        // attach to stream to the resource in the manifest
        l_ImageStream = l_Assembly.GetManifestResourceStream(l_Str);
        if (!(null == l_ImageStream))
        {
            // create a new bitmap from this stream and 
            // add it to the arraylist
            l_Bitmap = Bitmap.FromStream(l_ImageStream) as Bitmap;
            if (!(null == l_Bitmap))
            {
                int l_Index = Convert.ToInt32(l_Str.Substring(l_Str.Length - 6, 2));
                l_Index -= 1;
                if (l_Index < 0) l_Index = 0;
                if (l_Index > K_NB_IMAGE) l_Index = K_NB_IMAGE;
                m_ImageArray[l_Index] = l_Bitmap;
            }
            l_Bitmap = null;
            l_ImageStream.Close();
            l_ImageStream = null;
        } // if
    } // if
} // foreach

之后:

Assembly l_Assembly = Assembly.GetExecutingAssembly();

//Linq is the tops
m_ImageList = l_Assembly.GetManifestResourceNames()
    .Where(a => a.EndsWith(".png"))
    .OrderBy(b => b)
    .Select(c => l_Assembly.GetManifestResourceStream(c))
    .Where(d => d != null)  //ImageStream not null
    .Select(e => Bitmap.FromStream(e))
    .Where(f => f != null)  //Bitmap not null
    .ToList();

或者(查询语法):

Assembly l_Assembly = Assembly.GetExecutingAssembly();

//Linq is the tops
m_ImageList = (
    from resource in l_Assembly.GetManifestResourceNames()
    where resource.EndsWith(".png")
    orderby resource
    let imageStream = l_Assembly.GetManifestResourceStream(resource)
    where imageStream != null
    let bitmap = Bitmap.FromStream(imageStream)
    where bitmap != null)
    .ToList();

所以真的,真的大约皇宫有什么都不做皇宫SQL。这是有关增强它带到C#语言本身。

皇宫不是只是一个欧姆系统,作为乔纳森指出的,这带来了很多的功能编程的元素。它可以让你做一个很大的"数据库-y"的东西,在常规C#代码。这很难解释是如何令人难以置信的强大的认可。考虑如何更有固,精心设计的通用数据结构(例如清单、堆存、词典/哈,等等。) 包括在共同框架有所改善国家的发展现代语言。正是因为使用这些数据结构中是很常见和减少知识产权的开销的使用他们来说是一个巨大的好处。皇宫不会做任何你不能自己做的,但它使大量的操作更多的简单和容易得多。

考虑时间-荣幸,例如消除重复从非订购单。在一个低级的语言,比如C或C++你可能会有的排序的名单,并维护两个索引列表中删除重复.在语言与哈希(Java,C#,Javascript,Perl,等等。) 你可以创建一个哈希键是独特的价值,然后取键入一个新的名单。与皇宫你只能做到这一点:

int[] data = { 0, 1, 3, 3, 7, 8, 0, 9, 2, 1 };

var uniqueData = data.GroupBy(i => i).Select(g => g.Key);

因为皇宫真是异在sql服装,我使用的是它在一个项目,使异网要求继续单,它证明工作真的很好!

看看这些文章:http://www.aboutcode.net/2008/01/14/Async+WebRequest+Using+LINQ+Syntax.aspx http://blogs.msdn.com/wesdyer/archive/2008/01/11/the-marvels-of-monads.aspx

从第一条:

    var requests = new[] 
    {
        WebRequest.Create("http://www.google.com/"),
        WebRequest.Create("http://www.yahoo.com/"),
        WebRequest.Create("http://channel9.msdn.com/")
    };

    var pages = from request in requests
                select
                    from response in request.GetResponseAsync()
                    let stream = response.GetResponseStream()
                    from html in stream.ReadToEndAsync()
                    select new { html, response };

    foreach (var page in pages)
    {
        page(d =>
        {
            Console.WriteLine(d.response.ResponseUri.ToString());
            Console.WriteLine(d.html.Substring(0, 40));
            Console.WriteLine();
        });
    }

这一点是皇宫集您的查询到你主编程语言,允许你IDE为你提供一些设施(智能感知和调试的支持,例如),否则你就不会,并允许编译器的类型-检查你的SQL代码(这是不可能与正常的串查询)。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top