Довольно трудно сказать о лучшем решении для Вашей проблемы без деталей о данных и отношениях между Вашими моделями (таблицы). Общая идея является следующей: сохраните свои представления глупыми. Доберитесь все данные должны были представить представление в Вашем действии контроллеров. Внесите все изменения и вычисления в том же действии. Тогда в поле зрения используйте эти данные.
btw, если Вы говорите о проблеме N+1 тогда, читают больше о, 'включают', и 'присоединяется' к параметрам ActiveRecord.
string fullAppName = Assembly.GetCallingAssembly().GetName().CodeBase;
string fullAppPath = Path.GetDirectoryName(fullAppName);
You can use GetModuleFileName
In the below sample, the method GetExecutablePath
returns the location of the exe, and GetStartupPath
returns the directory of the exe.
using System;
using System.ComponentModel;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
class Program
{
[DllImport("coredll", SetLastError = true)]
public static extern uint GetModuleFileName(IntPtr hModule, StringBuilder lpFilename, [MarshalAs(UnmanagedType.U4)] int nSize);
[DllImport("coredll")]
public static extern uint FormatMessage([MarshalAs(UnmanagedType.U4)] FormatMessageFlags dwFlags, IntPtr lpSource, uint dwMessageId, uint dwLanguageId, out IntPtr lpBuffer, uint nSize, IntPtr Arguments);
[DllImport("coredll")]
public static extern IntPtr LocalFree(IntPtr hMem);
[Flags]
internal enum FormatMessageFlags : uint
{
AllocateBuffer = 256,
FromSystem = 4096,
IgnoreInserts = 512
}
public static string GetModuleFileName(IntPtr hModule)
{
StringBuilder lpFilename = new StringBuilder(short.MaxValue);
uint num = GetModuleFileName(hModule, lpFilename, lpFilename.Capacity);
if (num == 0)
{
throw CreateWin32Exception(Marshal.GetLastWin32Error());
}
return lpFilename.ToString();
}
private static Win32Exception CreateWin32Exception(int error)
{
IntPtr buffer = IntPtr.Zero;
try
{
if (FormatMessage(FormatMessageFlags.IgnoreInserts | FormatMessageFlags.FromSystem | FormatMessageFlags.AllocateBuffer, IntPtr.Zero, (uint)error, 0, out buffer, 0, IntPtr.Zero) == 0)
{
return new Win32Exception();
}
return new Win32Exception(error, Marshal.PtrToStringUni(buffer));
}
finally
{
if (buffer != IntPtr.Zero)
{
LocalFree(buffer);
}
}
}
public static string GetStartupPath()
{
return Path.GetDirectoryName(GetExecutablePath());
}
public static string GetExecutablePath()
{
return GetModuleFileName(IntPtr.Zero);
}
}
Windows Mobile не имеет понятия текущей папки. «Текущая папка» обычно всегда устанавливается как корень файловой системы, независимо от того, где находится ваше приложение.
Чтобы получить путь к вашему приложению, вы можете использовать Assembly.GetExecutingAssembly ()
, и свойство CodeBase
или GetName ()
метод
Не боритесь с системой.
Microsoft не хочет, чтобы вы использовали папку программных файлов для чего-либо, кроме сборок. Файлы конфигурации должны находиться в Application Data, Save files и т. Д., О которых пользователи должны знать, go в My Documents.
Ответ jalf будет работать, но вы боретесь с системой. Если это не действительно веская причина, по которой вы хотите знать, в какой папке находится ваша сборка, я бы посоветовал отказаться от этого.