1
내 WP8.1 응용 프로그램에 로컬 데이터베이스가있는 최상의 솔루션을 찾고 있습니다. 나는 표준 WP8.1 (비 SL) 및 Visual Studio를 사용하고Windows Phone 8.1 (appx) 데이터베이스 솔루션
2013
내가 SQLite는 살펴본하지만 난 내 응용 프로그램에서 작동하도록 얻을 관리 할 수 / 비주얼 스튜디오 .
내가 SQLite를 사용할 수 있다면, 나는가는 길을 알려줄 누군가가 필요합니다. 그렇지 않으면 나에게 최고의 솔루션을 참조하십시오. 사전에
감사합니다! (내가 SL에서 이전에 사용했다) 내가 만들 수있는 방법을 찾을 수 없습니다
public class ContactsRepository : IContactsRepository
{
SQLiteAsyncConnection _connection = null;
static ContactsRepository _repository = null;
private ContactsRepository()
{
}
public async Task Initialize()
{
_connection = new SQLiteAsyncConnection(Constants.DATABASE_FILE_NAME);
await EnsureTableExist<ContactReference>(_connection);
}
public static ContactsRepository Instance
{
get
{
if (_repository == null)
{
_repository = new ContactsRepository();
}
return _repository;
}
}
public async Task Add(Category category, Contact contact)
{
var result = await _connection.Table<ContactReference>().Where(c => c.ContactId == contact.Id).FirstOrDefaultAsync();
if (result != null)
{
result.CategoryName = category.Name;
await _connection.UpdateAsync(result);
}
else
{
await _connection.InsertAsync(new ContactReference()
{
CategoryName = category.Name,
ContactId = contact.Id
});
}
}
public async Task Update(Category category, Contact contact)
{
var result = await _connection.Table<ContactReference>().Where(c => c.ContactId == contact.Id).FirstOrDefaultAsync();
Debug.Assert(result != null);
if (result == null)
{
throw new Exception("Unable to update category. Candidate not found");
}
if (result != null)
{
result.CategoryName = category.Name;
await _connection.UpdateAsync(result);
}
}
public async Task<ObservableCollection<Contact>> Get(string categoryName)
{
var result = new ObservableCollection<Contact>();
var query = _connection.Table<ContactReference>().Where(c => c.CategoryName == categoryName);
var queryResult = await query.ToListAsync();
foreach(var contact in queryResult)
{
var phoneContacts = ResourceLocator.Instance[typeof(ObservableCollection<Contact>)] as ObservableCollection<Contact>;
var phoneContact = phoneContacts.Where(c => c.Id == contact.ContactId).FirstOrDefault();
Debug.Assert(phoneContact != null);
if (phoneContact != null)
{
result.Add(phoneContact);
}
}
return result;
}
public async Task<ObservableCollection<ContactReference>> Get()
{
var result = new ObservableCollection<ContactReference>();
var query = _connection.Table<ContactReference>();
var queryResult = await query.ToListAsync();
foreach (var contact in queryResult)
{
result.Add(contact);
}
return result;
}
private async Task EnsureTableExist<T>(SQLiteAsyncConnection connection) where T : new()
{
bool noTableExists = false;
try
{
var query = await connection.Table<T>().FirstOrDefaultAsync();
}
catch (SQLiteException ex)
{
if (ex.Message.Contains("no such table"))
{
noTableExists = true;
}
}
if (noTableExists)
{
await connection.CreateTableAsync<T>();
}
}
}
첫째, 내가 해봤 System.Data.Linq : 여기 – silentw
나는 어떤 형태로든 데이터베이스를 사용할 수 없으므로 XML 또는 JSON에 대해 생각해 보았다. 하지만 관계형 데이터베이스가 필요하기 때문에 데이터베이스를 선호합니다. – silentw
당신이 정확히 무엇을 공유하지 않았기 때문에 지금까지 노력하고 정확히 'didn를 누군가가 당신을을 downvoted 이유는 모르겠지만, 그것 수 있습니다 ... 난을 downvoted 대신의 도움이있어 이유를 알고 – silentw