我有一些我想获得本地化名称的药物,但是我无法获得他们的本地化名称(在回报中它们是空白的)。
这是查询(在运行时)。
SELECT m.Id as Id, m.Name as Name, lm.Name as ProductName
FROM Medicine m
INNER JOIN LocalizedMedicine lm
ON lm.MeId = m.Id
AND lm.LanguageCode = 'en-US'
ORDER BY m.Name
这是我的课程。
public class LocalizedMedicine
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
[Indexed("LocMedName", 0)]
public string Name { get; set; }
public string LanguageCode { get; set; }
public int MeId { get; set; }
}
public class Medicine : ObservableObject
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
/// <summary>
/// The universal Latin medical name.
/// </summary>
public string Name { get; set; }
/// <summary>
/// The primary Gene that this medicine uses.
/// </summary>
public int GeneId { get; set; }
[Ignore]
public Gene GeneUsed { get; set; }
private string productName;
/// <summary>
/// The localized product name. It retrieves the
/// localized name from AppResources if it is null.
/// </summary>
[Ignore]
public string ProductName
{
get
{
// old attempt
//if (productName == null)
// productName = AppResources.ResourceManager.GetString(Name);
return productName;
}
set
{
productName = value;
NotifyPropertyChanged("ProductName");
}
}
/// <summary>
/// Does a reference comparison and Name comparison, since the names (latin names)
/// should be unique.
/// </summary>
/// <param name="m"></param>
/// <returns></returns>
public override bool Equals(object m)
{
if (m == null) return false;
if (m == this) return true;
if (((Medicine)m).Name == this.Name) return true;
return false;
}
}
以下是我打电话的方式(在PCL中)
public IEnumerable<Medicine> GetAllMedicines(CultureInfo cultureInfo)
{
string langCode = cultureInfo.Name;
// get all of the medicines and join LocalizedMedicine on MeId = med.Id
// and LanguageCode = langCode
var query = database.QueryAsync<Medicine>(
"SELECT m.Id as Id, m.Name as Name, lm.Name as ProductName " +
"FROM Medicine m " +
"INNER JOIN LocalizedMedicine lm ON lm.MeId = m.Id AND lm.LanguageCode = " + "'" + langCode + "' " +
"ORDER BY m.Name"
);
query.Wait();
var result = query.Result;
return result;
}
答案 0 :(得分:0)
从&#34; ON&#34;更改查询条件到&#34;在哪里&#34;并从Medicine类中删除了ignore属性。 woops。