1) Да 2) Вам понадобятся эти данные для доступа к информации из AX.
using Microsoft.Dynamics.AX.Framework.Linq.Data;
using U23 = Microsoft.Dynamics.AX.ManagedInterop;
using U22 = Microsoft.Dynamics.AX.Framework.Linq.Data;
using Microsoft.Dynamics.Portal.Application.Proxy;
Наконец, вот моя основная схема моего уровня доступа на C#.
private U23.Session _axSession = new U23.Session();
public U23.Session Connection
{
get
{
return this._axSession;
}
}
/// <summary>
/// Checks to see if the AX session is connected. If it's null we return false.
/// Then we check to see if it's logged in, then return true. Otherwise it's not logged in.
/// </summary>
public bool Connected
{
get
{
if (this._axSession == null)
{
return false;
}
else if (this._axSession.isLoggedOn())
{
return true;
}
return false;
}
}
/// <summary>
/// This connects to the AX session. If it's already connected then we don't need to connect
/// again, so we return true. Otherwise we'll try to initiate the session.
/// </summary>
/// <returns>
/// True: Connection openned successfully, or was already open.
/// False: Connection failed.
/// </returns>
public bool OpenConnection()
{
if (this.Connected)
{
return true;
}
else
{
try
{
_axSession.Logon(null, null, null, null);
return true;
}
catch
{
return false;
}
}
}
/// <summary>
/// If the session is logged on we will try to close it.
/// </summary>
/// <returns>
/// True: Connection closed successfully
/// False: Problem closing the connection
/// </returns>
public bool CloseConnection()
{
bool retVal = false;
if (this.Connection.isLoggedOn())
{
try
{
_axSession.Logoff();
retVal = true;
}
catch
{
retVal = false;
}
}
else
{
retVal = true;
}
this.Connection.Dispose();
return retVal;
}
Тогда для доступа к определенным функциям в AX вам нужно:
public Somethings GetSomethingsById(int id)
{
Somethings retVal = new Somethings();
U22.QueryProvider provider = new U22.AXQueryProvider(null);
U22.QueryCollection<Somethings> somethings = new U22.QueryCollection<Somethings>(provider);
var somethings2 = somethings.Where(x => x.SomethingId == id);
retVal = somethings2.FirstOrDefault();
return retVal;
}
Наконец, если вы хотите обновить что-то:
public bool UpdateSomething(Something something)
{
U23.RuntimeContext.Current.TTSBegin();
try
{
if (something.Count == 0)
{
something.Delete();
}
something.Update();
U23.RuntimeContext.Current.TTSCommit();
return true;
}
catch
{
U23.RuntimeContext.Current.TTSAbort();
return false;
}
}
, но убедитесь, что вы выбрав Something
с .ForUpdate(), когда вы планируете его обновлять.
Вам также нужно будет добавить любые объекты, которые вы планируете использовать для прокси-сервера приложений (например, EPApplicationProxies), и ссылаться на них из вашего проекта.
Какая ссылка на сборку требуется для Dynamics –
Это нормально, я получил ее. Спасибо за помощь . –