AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 01.01.2009, 18:06   #1  
Blog bot is offline
Blog bot
Участник
 
25,643 / 848 (80) +++++++
Регистрация: 28.10.2006
gatesasbait: LINQ
Источник: http://gatesasbait.spaces.live.com/B...B9F5!289.entry
==============

 

Источник: http://gatesasbait.spaces.live.com/B...B9F5!289.entry
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
Старый 01.01.2009, 18:06   #2  
Blog bot is offline
Blog bot
Участник
 
25,643 / 848 (80) +++++++
Регистрация: 28.10.2006
gatesasbait: LINQ (Part 1, Part 2)
Источник: http://gatesasbait.spaces.live.com/B...B9F5!288.entry
==============

 
Happy New Year!
 
LINQ is used in SSRS reports in AX 2009 and is likely to be used more widely in the upcoming AX 2011. LINQ's purpose is to allow .Net languages to query collections as you would tables and views in SQL. Of course, Microsoft added to that a series of 'LINQ to SQL' capabilities to allow developers to query database tables as if they were collections. Here's the most basic examples showing a select statement running on a standard .Net List collection:
 
Код:
using System;
using System.Linq;
using System.Collections.Generic;
using System.Windows.Forms;
 
public class Test 
{
    public static void Main() 
    {
        List aList1 = new List(); 
        aList1.Add(new AnElement() { aMember1 = 5, aMember2 = 6 }); 
        aList1.Add(new AnElement() { aMember1 = 4, aMember2 = 7 }); 
  
        IEnumerable query =
            from item in aList1
            where item.aMember1 == 5
            select item;
 
        foreach (AnElement item in query)
        {
            MessageBox.Show(item.aMember2.ToString());
        }
    }
}
public class AnElement 
{
    public int aMember1; 
    public int aMember2; 
}
 
Dynamics Ax developers will notice the inverted syntax of:
    from item in aList1
    where item.aMember1 == 5
    select item;
instead of
    select *
    from A
    where A.B == C
as well as the added 'in' keyword.
 
Part 2 to follow


Источник: http://gatesasbait.spaces.live.com/B...B9F5!288.entry

Источник: http://gatesasbait.spaces.live.com/B...B9F5!289.entry
==============


Now to join two collections together:

//ref: http://www.hookedonlinq.com/JoinOperator.ashx
Код:
using System;
using System.Linq;
using System.Collections.Generic;
using System.Windows.Forms;
 
public class Test
{
    public static void Main()
    {
        List customers = new List() { 
            new Customer {Key = 1, Name = "Gottshall" },
            new Customer {Key = 2, Name = "Valdes" }};
 
        List orders = new List() {
            new Order {Key = 1, OrderNumber = "Order 1" },
            new Order {Key = 1, OrderNumber = "Order 2" },
            new Order {Key = 2, OrderNumber = "Order 3" }};
 
        var query = 
            from cust in customers
            join sale in orders on cust.Key equals sale.Key
            where cust.Name == "Gottshall"
            select new { cust.Name, sale.OrderNumber };
 
        foreach (var line in query)
        {
            MessageBox.Show(line.Name.ToString()+" "+line.OrderNumber.ToString());
        }
    }
}
public class Customer
{
    public int Key;
    public string Name;
}
public class Order
{
    public int Key;
    public string OrderNumber;
}
The output is
'Gottshall Order 1'
'Gottshall Order 2'

LINQ is really really cool. Here's why. In my previous post, I had explicitely typed the query with 'IEnumerable'. But here I can't do that, because the resulting join of Customer and Order is of a type that isn't defined, and I'd rather not bother defining a new type for every kind of return I'm going to get. So we use the keyword 'var' to both define the 'IEnumerable' query as well as each of its lines in the foreach loop.

'var' allows .Net to create its own type as needed. It's called 'implicit types'. In theory I'm sure its very different to the Ax 'Object' or 'Common' types, but in practice its pretty close.

Part 3 to follow




Источник: http://gatesasbait.spaces.live.com/B...B9F5!289.entry
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
gatesasbait: AP Posting fails because of security setup in Dynamics Ax 4 Blog bot DAX Blogs 0 03.02.2009 02:07
gatesasbait: How to temporarily suppress infolog messages in Dynamics Ax (deux) Blog bot DAX Blogs 7 28.01.2009 17:45
gatesasbait: DAX and Visual Studio, Future reserved words Blog bot DAX Blogs 0 11.04.2008 18:05
gatesasbait: Local DAX installation method also works for Dynamics Ax 5.0 Build 366 Blog bot DAX Blogs 0 28.11.2007 18:51
Dynamics AX: LINQ, C# 3.0 - Something looks familiar Blog bot DAX Blogs 5 13.11.2007 14:41

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 21:23.