Suresh Rajana

Suresh Rajana

  • NA
  • 43
  • 6.9k

how to join and retrive the result of the mvvm database

Mar 31 2017 1:52 AM
 iam new to xamarin.froms
 i have develop a xamarin.forms shared project and  i want to join the table fields with conditions  and make methos with the joint operations,
 
my sample join opeation one doctors names will be display on the spcialization in search bar. how  can i do that....
in that i have 2 tables

public class Doctors :IObject

{

public Doctors()

{

}

[PrimaryKey, AutoIncrement]

public int ID { get; set; }

[MaxLength(25)]

public string Names { get; set; }

[MaxLength(40)]

public string Specialization { get; set; }

[MaxLength(40)]

public string Username { get; set; }

[MaxLength(40)]

public string Email { get; set; }

[MaxLength(40)]

public int Phoneno { get; set; }

[MaxLength(20)]

public string Password { get; set; }

[MaxLength(30)]

public string Confirmpassword { get; set; }

[MaxLength(30)]

public string Address { get; set; }

//------------------second table---------------------------//

public Patient()

{

}

[PrimaryKey, AutoIncrement]

public int ID { get; set; }

[MaxLength (40)]

public string Name { get; set; }

[MaxLength(40)]

public string Username { get; set; }

[MaxLength(40)]

public string Password { get; set; }

[MaxLength(40)]

public string Confirmpassword { get; set; }

[MaxLength(40)]

public string Email { get; set; }

[MaxLength(20)]

public int Phoneno { get; set; }

[MaxLength(20)]

 
 
 
///////////////////--------------------and my  generic database repositry files is----------------------/////
 

public class ItemDatabaseGeneric

{

static object locker = new object();

SQLiteConnection database;

public ItemDatabaseGeneric()

{

database = new SQLiteConnection(databasePath);

database.CreateTable<Patient>();

database.CreateTable<Doctors>();

database.CreateTable<Clinicorhospital>();

}

string databasePath

{

get

{

var dbName = "ItemsSQLite.db3";

#if __IOS__

string folder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

folder = Path.Combine(folder, "..", "Library");

var databasePath = Path.Combine(folder, dbName);

#else

#if __ANDROID__

string folder = Environment.GetFolderPath (Environment.SpecialFolder.Personal);

var databasePath = Path.Combine(folder, dbName);

#else

// WinPhone

var databasePath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, dbName);;

#endif

#endif

return databasePath;

}

}

public IEnumerable<T> GetObjects<T>() where T : IObject, new()

{

lock(locker)

{

return (from i in database.Table<T>() select i).ToList();

}

}

public IEnumerable<T> GetFirstObjects<T>() where T : IObject, new()

{

lock (locker)

{

return database.Query<T>("SELECT * FROM Item WHERE Name = '+ Name +'");

}

}

public IEnumerable<T>Getnameobjects<T>() where T:IObject,new()

{

lock(locker)

{

return database.Query<T>("select my_column from Item WHERE Name = '+ name +'");

}

}

// public IEnumerable<T> query = from dt in dtEmployees.AsEnumerable()

// select dt.Field<string>("Name");

public T GetObject<T>(string username) where T : IObject,new()

{

lock(locker)

{

return database.Table<T>().FirstOrDefault(X => X.Username == username);

}

}

//public Task> GetPropertiesAsync()

//{

// return database.Table().ToListAsync();

//}

public T GetObject<T>(string username,string password) where T : IObject, new()

{

lock (locker)

{

return database.Table<T>().FirstOrDefault(X => X.Username == username&& X.Password==password);

}

}

public int SaveObject<T>(T obj) where T : IObject

{

lock (locker)

{

if (obj.ID != 0)

{

database.Update(obj);

return obj.ID;

}

else

{

return database.Insert(obj);

}

}

}

public int DeleteObject<T>(int id) where T : IObject, new()

{

lock (locker)

{

return database.Delete<T>(id);

}

}

}}

 
 

Answers (1)