here ,i am using wpf .in my code there is one folder named by datacontect:and it contain code as below:
public interface IAccountCategoryDataSource
{
bool Add(AccountCategory accountCategory);
bool Update(AccountCategory accountCategory);
bool Remove(AccountCategory accountCategory);
AccountCategory GetById(int id);
AccountCategory GetByName(string name);
IEnumerable<AccountCategory> GetByParentCategory(AccountCategory category);
IEnumerable<AccountCategory> GetTopLevelCategories();
IEnumerable<AccountCategory> GetBySearchTerm(string searchTerm);
IEnumerable<AccountCategory> GetAll();
event EventHandler<ObjectAddedEventArgs> AccountCategoryAdded;
event EventHandler<ObjectUpdatedEventArgs> AccountCategoryUpdated;
event EventHandler<ObjectRemovedEventArgs> AccountCategoryRemoved;
}
ther is also other folder datasource: here datasource is related to the above file
public class AccountCategoryDataSource : IAccountCategoryDataSource
{
public int ReferenceCountOf(AccountCategory accountCategory)
{
int count = 0;
string query = "select count(*) from account_categories where parent_category=" + accountCategory.Id
+ " union select count(*) from accounts where category=" + accountCategory.Id;
DataTable dataTable = SQLiteHelper.ExecuteQuery(query);
foreach (DataRow row in dataTable.Rows)
{
count += Convert.ToInt32(row[0]);
}
return count;
}
#region IAccountCategoryDataSource Members
public bool Add(AccountCategory accountCategory)
{
string query = "insert into account_categories(name, description, parent_category) values("
+ "'" + accountCategory.Name + "', "
+ "'" + accountCategory.Description + "', "
+ accountCategory.ParentCategory.Id
+ ")";
accountCategory.Id = SQLiteHelper.ExecuteInsert(query);
if (accountCategory.Id > 0)
{
if (AccountCategoryAdded != null)
{
AccountCategoryAdded(this, new ObjectAddedEventArgs(accountCategory));
}
return true;
}
return false;
}
public bool Update(AccountCategory accountCategory)..................
and this related to the model floder’s accountcategory class
public class AccountCategory : IDataErrorInfo, IValidable
{
#region State Properties
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public AccountCategory ParentCategory { get; set; }
public bool Builtin { get; set; }
}
and for execution :helper class
public class SQLiteHelper
{
public static DataTable ExecuteQuery(string query)
{
DataTable dataTable = new DataTable();
SQLiteConnection conn = new SQLiteConnection(Settings.Default["DBConnectionString"].ToString());
using (SQLiteCommand cmd = new SQLiteCommand(query, conn))
{
conn.Open();
SQLiteDataReader reader = cmd.ExecuteReader();
dataTable.Load(reader);
reader.Close();
conn.Close();
}
return dataTable;
}..........................
plz explain brief role of data contract.and how it interact with helper,model,and dataSouce . is it provide linq to sql concept?
DataContract is a WCF concept. It is unrelated to WPF (until it is communicating with WCF).
From your code, seems like it it just a Folder which contain Data Access Layer classes and seems unrelated to WCF