This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi, is there a simple way to write an update query then the following: Do you have to list every attribute you are wanting to update? And without intellience..? var query = new Query(typeof(Contribution), Entity.Attribute("Title").Like("S%")); _unitOfWork.Update(query, _attributes);
|
|
|
Yes, you do need to list every attribute you want to update. If you are using the designer, you can get some measure of Intellisense using the attribute name constants e.g. attributes = new Dictionary<...> { You can also pass an object (whose properties will become the attributes) instead of the dictionary. So you could create a "update" type with only the properties you want to update: public class TitleUpdate { _unitOfWork.Update(query, new TitleUpdate { Title = "Foo" }); |
|
|
Thanks Ivan, Also what's wrong with this query? I'm getting the error can't convert from bool to query expression. var query = new Query(typeof(Application), Entity.Attribute("ApplicationId") == application.Id); |
|
|
There doesn't seem to be anything wrong with that expression -- it looks fine. You are getting the error at compile time, is that right? Could you post the full code? Thanks! |
|
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mindscape.LightSpeed;
using Mindscape.LightSpeed.Querying;
using Mindscape.LightSpeed.Linq;
namespace IRL.Help.BusinessLogic
{
public class ApplicationRepository : DataAccessBase
{
///
/// Get all applications
///
///
public List GetAll()
{
using (ModelUnitOfWork uow = Context.CreateUnitOfWork())
{
return (from a in uow.Applications
select a).ToList();
}
}
///
/// Get application
///
///
///
public Application Get(int id)
{
using (ModelUnitOfWork uow = Context.CreateUnitOfWork())
{
return uow.FindOne(id);
}
}
///
/// Save application
///
/// application
/// application id
public int Save(Application application)
{
if (application.Id == null || application.Id == 0)
return Create();
else
return Update();
}
///
/// Create application
///
/// application
/// application id
private int Create(Application application)
{
using (ModelUnitOfWork uow = Context.CreateUnitOfWork())
{
uow.Add(application);
uow.SaveChanges();
return application.Id;
}
}
///
/// Update application
///
/// application
/// application id
private int Update(Application application)
{
using (ModelUnitOfWork uow = Context.CreateUnitOfWork())
{
var query = new Query(typeof(Application), Entity.Attribute("ApplicationId") == application.Id);
uow.Update(query, application);
return application.Id;
}
}
}
}
|
|
|
using System;using System.Collections.Generic;using System.Linq;using System.Text;using Mindscape.LightSpeed;using Mindscape.LightSpeed.Querying;using Mindscape.LightSpeed.Linq;namespace IRL.Help.BusinessLogic{ public class ApplicationRepository : DataAccessBase{ /// <summary> /// Get all applications /// </summary> /// <returns></returns>public List<Application> GetAll(){ using (ModelUnitOfWork uow = Context.CreateUnitOfWork()){ return (from a in uow.Applicationsselect a).ToList<Application>();} } /// <summary> /// Get application /// </summary> /// <param name="id"></param> /// <returns></returns>public Application Get(int id){ using (ModelUnitOfWork uow = Context.CreateUnitOfWork()){ return uow.FindOne<Application>(id);} } /// <summary> /// Save application /// </summary> /// <param name="application">application</param> /// <returns>application id</returns>public int Save(Application application){ if (application.Id == null || application.Id == 0) return Create(); elsereturn Update();} /// <summary> /// Create application /// </summary> /// <param name="application">application</param> /// <returns>application id</returns>private int Create(Application application){ using (ModelUnitOfWork uow = Context.CreateUnitOfWork()){ uow.Add(application); uow.SaveChanges(); return application.Id;} } /// <summary> /// Update application /// </summary> /// <param name="application">application</param> /// <returns>application id</returns>private int Update(Application application){ using (ModelUnitOfWork uow = Context.CreateUnitOfWork()){ var query = new Query(typeof(Application), Entity.Attribute("ApplicationId") == application.Id);uow.Update(query, application); return application.Id;} } } } |
|
|
my bad. This worked: var query = new Mindscape.LightSpeed.Querying.Query(typeof(Application), Entity.Attribute("ApplicationId") == application.Id); |
|
|
Odd: you shouldn't normally have to namespace-qualify it. Is there another Query class somewhere in your code? Glad to hear it's working for you now, anyway! |
|