English 中文(简体)
如何绘制横跨几个表格的“设计、铺设”图
原标题:How to map a Dictionary<string, string> spanning several tables

我有4个表格:

CREATE TABLE [Languages]
(
  [Id] INTEGER IDENTITY(1,1) NOT NULL,
  [Code] NVARCHAR(10) NOT NULL,
  PRIMARY KEY ([Id]),
  UNIQUE INDEX ([Code])
);

CREATE TABLE [Words]
(
  [Id] INTEGER IDENTITY(1,1) NOT NULL,
  PRIMARY KEY ([Id])
);

CREATE TABLE [WordTranslations]
(
  [Id] INTEGER IDENTITY(1,1) NOT NULL,
  [Value] NVARCHAR(100) NOT NULL,
  [Word] INTEGER NOT NULL,
  [Language] INTEGER NOT NULL,
  PRIMARY KEY ([Id]),
  FOREIGN KEY ([Word]) REFERENCES [Words] ([Id]),
  FOREIGN KEY ([Language]) REFERENCES [Languages] ([Id])
);

CREATE TABLE [Categories]
(
  [Id] INTEGER IDENTITY(1,1) NOT NULL,
  [Word] INTEGER NOT NULL,
  PRIMARY KEY ([Id]),
  FOREIGN KEY ([Word]) REFERENCES [Words] ([Id])
);

因此,通过语言关系获得“语言”——和“语言”——和“语言关系”。

与此类似:

SELECT TOP 1 wt.Value
FROM [Categories] AS c
LEFT JOIN [WordTranslations] AS wt ON c.Word = wt.Word
WHERE wt.Language = (
  SELECT TOP 1 l.Id
  FROM [Languages]
  WHERE l.[Code] = N en-US 
)
AND c.Id = 1;

从而将Id = 1类的“美国”译文复封。

我的问题是,如何利用以下类别来绘制这一地图:

public class Category
{
  public virtual int Id { get; set; }
  public virtual IDictionary<string, string> Translations { get; set; }
}

采用上文KLQ的做法,就是:

Category category = session.Get<Category>(1);

string name = category.Translations["en-US"];

现在,“姓名”将包含美国名下的类别名称。

类别按照类别表排列。

你们怎样做,甚至可能这样做?

问题回答

如果你使用准则,你就应当能够放弃这样的东西:

public Category GetCategory(int categoryId)
{ 
    var translations = from c in db.Categories
                       join wt in db.WordTranslations on c.Word equals wt.Word
                       join l in db.Languages on l.Id equals wt.Language
                       where c.Id == categoryId
                       select new { Key=l.Code, Value=wt.Word };
    return new Category { Id=categoryId, Translations=translations.ToDictionary() };
}

我没有对此进行汇编,因此,你可能需要与辛迪加合作,以取得正确结果,但从概念上来说,这应当使你了解你们的需要。

您是否考虑使用<> SetResult Transformer。 国民经济部为向班级或其他结构绘制结果集提供这一功能。 利用Alisa ToEntityMap的转子,将每一行转化为财产的一个字典,这可能是你所期望的。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签