我陷入了加入,我无法弄清楚问题出在哪里,我有那些表
public class Themes
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public String ThemeName { get; set; }
public String ThemeDesc { get; set; }
public int ThemeImg { get; set; }
public String ThemeCategory { get; set; }
public String ThemeSubcategory { get; set; }
}
public class MusicItems
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public String Name { get; set; }
public String Tension { get; set; }
public String Category { get; set; }
public String Subcategory { get; set; }
public int ResId { get; set; }
public int LoopStart { get; set; }
}
public class Playlist
{
public String Name { get; set; }
public int ResId { get; set; }
public int LoopStart { get; set; }
}
public class MusicInThemes
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public int ResId { get; set; }
public int ThemeId { get; set; }
}
我想加入MusicItems与MusicInThemes ,以获取属于主题的所有音乐文件详细信息。到目前为止,我已尝试这些崩溃我的应用程序:
var query = from MusicItem in database.Table<MusicItems>()
join Theme in database.Table<MusicInThemes>()
on MusicItem.ResId equals Theme.ResId
where Theme.ThemeId == ThemeID
select new Playlist{Name = MusicItem.Name, ResId = MusicItem.ResId ,LoopStart = 0};
return query.ToList();
// and
return database.Table<MusicItems>()
.Join(database.Table<MusicInThemes>().Where(t => t.ThemeId == ThemeID)
,m => m.ResId
,t => t.ResId
,(m,t) => new Playlist{Name = m.Name, ResId = m.ResId ,LoopStart = m.LoopStart})
.ToList();
这是我得到播放列表的代码:(我有2个按钮.btnTheme1显示主题的一些信息并保存som主题变量,然后loadTheme按钮尝试从所选主题中提取歌曲)
ThemeImage = view.FindViewById<ImageView> (Resource.Id.imgThemeImage);
ThemeDesc = view.FindViewById<TextView> (Resource.Id.txtDesc);
Button btnTheme1 = view.FindViewById<Button> (Resource.Id.btnTheme1);
//Button btnTheme2 = view.FindViewById<Button> (Resource.Id.btnTheme2);
Button btnLoadTheme = view.FindViewById<Button> (Resource.Id.btnLoadTheme);
musicFiles.AllThemes = mydata.GetAllThemes ();
Console.WriteLine("Themes Count:"+musicFiles.AllThemes.Count);
var ListSEbuttons = new List<Button> {
{ btnTheme1 },
};
for (i=0;i<ListSEbuttons.Count();i++){
var button = ListSEbuttons[i];
button.Text = SelectedThemeName = musicFiles.AllThemes [i].ThemeName;
SelectedThemeImageId = musicFiles.AllThemes [i].ThemeImg;
button.Tag = i;
SelectedThemeId = musicFiles.AllThemes [i].Id;
button.Click += ButtonOnClick;
}
btnTheme1.PerformClick ();
btnLoadTheme.Click += (sender, e) => {
Low = mydata.GetPlaylist(SelectedThemeId,"low"); // this is where the crash happens
...
}
private void ButtonOnClick(object sender, EventArgs eventArgs)
{
var button = sender as Button;
if (button != null)
{
var index = (int)button.Tag;
Console.WriteLine("List pos for sound effect: "+musicFiles.AllThemes [index].ThemeImg);
button.RequestFocus();
ThemeDesc.Text = musicFiles.AllThemes [index].ThemeDesc;
//ThemeImage.SetImageResource (musicFiles.AllThemes [index].ThemeImg);
}
}
//ignore the "low" parameter i never use it for now
请咨询
Debug Log:
...
[Mono] Assembly Ref addref Music[0xb95c8210] -> Newtonsoft.Json[0xb95ca100]: 2
[Mono] The request to load the retargetable assembly mscorlib v2.0.5.0 was remapped to mscorlib v2.0.5.0
[Mono] Assembly Ref addref Newtonsoft.Json[0xb95ca100] -> mscorlib[0xb9406208]: 7
[Mono] Assembly Ref addref System.Core[0xb960c248] -> System[0xb972dd18]: 4
[MediaPlayer-JNI] MediaPlayer finalized without being released
[MediaPlayer-JNI] MediaPlayer finalized without being released
[MediaPlayer-JNI] MediaPlayer finalized without being released
[MediaPlayer-JNI] MediaPlayer finalized without being released
[Mono] GC_OLD_BRIDGE num-objects 44 num_hash_entries 47 sccs size 47 init 0.00ms df1 0.19ms sort 0.30ms dfs2 1.39ms setup-cb 0.01ms free-data 0.12ms links 3/3/3/1 dfs passes 94/50
[Mono] GC_MINOR: (Nursery full) pause 19.83ms, total 19.96ms, bridge 11.96ms promoted 784K major 1072K los 8K
[Mono] GC_OLD_BRIDGE num-objects 44 num_hash_entries 47 sccs size 47 init 0.00ms df1 0.19ms sort 0.30ms dfs2 1.39ms setup-cb 0.01ms free-data 0.12ms links 0/0/0/0 dfs passes 0/0
[Mono] GC_MINOR: (Nursery full) pause 11.56ms, total 11.67ms, bridge 0.17ms promoted 368K major 1440K los 8K
[] * Assertion at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/mono/mono/metadata/sgen-stw.c:68, condition `info->stack_start >= info->stack_start_limit && info->stack_start < info->stack_end' not met
[mono-rt] Stacktrace:
[mono-rt]
[mono-rt] at <unknown> <0xffffffff>
[mono-rt] at (wrapper managed-to-native) object.__icall_wrapper_mono_array_new_specific (intptr,int) <IL 0x00022, 0xffffffff>
[mono-rt] at System.Collections.Concurrent.SplitOrderedList`2<string, System.Collections.Generic.KeyValuePair`2<string, SQLite.PreparedSqlLiteInsertCommand>>..ctor (System.Collections.Generic.IEqualityComparer`1<string>) <IL 0x00006, 0x0004b>
[mono-rt] at System.Collections.Concurrent.ConcurrentDictionary`2..ctor (System.Collections.Generic.IEqualityComparer`1<TKey>) <IL 0x0000f, 0x000a6>
[mono-rt] at System.Collections.Concurrent.ConcurrentDictionary`2..ctor () <IL 0x00006, 0x0006b>
[mono-rt] at SQLite.TableMapping..ctor (System.Type,SQLite.CreateFlags) [0x0019d] in c:\Users\Exoskeletor\Documents\Projects\Music\Music\Helpers\SQLite.cs:1755
[mono-rt] at SQLite.SQLiteConnection.GetMapping (System.Type,SQLite.CreateFlags) [0x00036] in c:\Users\Exoskeletor\Documents\Projects\Music\Music\Helpers\SQLite.cs:304
[mono-rt] at SQLite.TableQuery`1..ctor (SQLite.SQLiteConnection) [0x00010] in c:\Users\Exoskeletor\Documents\Projects\Music\Music\Helpers\SQLite.cs:2473
[mono-rt] at SQLite.SQLiteConnection.Table<T> () [0x00001] in c:\Users\Exoskeletor\Documents\Projects\Music\Music\Helpers\SQLite.cs:768
[mono-rt] at Music.DataManager.DatabaseUpdates.GetPlaylist (int,string) [0x00027] in c:\Users\Exoskeletor\Documents\Projects\Music\Music\Helpers\DataManagerHelper.cs:288
[mono-rt] at Music.Music_SelectTheme/<>c__DisplayClass2.<OnCreateView>b__1 (object,System.EventArgs) [0x00001] in c:\Users\Exoskeletor\Documents\Projects\Music\Music\Music_SelectTheme.cs:77
[mono-rt] at Android.Views.View/IOnClickListenerImplementor.OnClick (Android.Views.View) [0x0000d] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/Mono.Android/platforms/android-15/src/generated/Android.Views.View.cs:1615
[mono-rt] at Android.Views.View/IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/Mono.Android/platforms/android-15/src/generated/Android.Views.View.cs:1582
[mono-rt] at (wrapper dynamic-method) object.a2a00f7c-dc24-4757-ba0d-9fa6ea56b30a (intptr,intptr,intptr) <IL 0x00017, 0x0001f>
[mono-rt] at (wrapper native-to-managed) object.a2a00f7c-dc24-4757-ba0d-9fa6ea56b30a (intptr,intptr,intptr) <IL 0x00023, 0xffffffff>
[mono-rt]
[mono-rt] =================================================================
[mono-rt] Got a SIGSEGV while executing native code. This usually indicates
[mono-rt] a fatal error in the mono runtime or one of the native libraries
[mono-rt] used by your application.
[mono-rt] =================================================================
[mono-rt]
[libc] Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 1385 (Music.Music)
答案 0 :(得分:14)
SQLite
目前不支持通过Linq
加入。我不得不使用这样的查询语法:
var q = database.Query<MusicItems>(
"select MI.Name, MI.ResId, MI.Tension from MusicItems MI"
+ " inner join MusicInThemes MT"
+ " on MI.ResId = MT.ResId where MT.ThemeId = ?",
ThemeID).ToList();
return q.Select(x => new Playlist { Name = x.Name, ResId = x.ResId, LoopStart = x.LoopStart });
答案 1 :(得分:1)
在查询前使用'@'符号将使其看起来更简单,更具可读性。
var musicFiles = database.Query<MusicItems>(@"select MI.Name, MI.ResId,
MI.Tension from MusicItems MI inner join MusicInThemes MT on
MI.ResId = MT.ResId where MT.ThemeId = ?",
ThemeID).ToList();