我有以下代码:
using System;
using System.Collections.Generic;
using System.Text;
using ProjectBase.Utils;
namespace EnterpriseSample.Core.Domain
{
public class Notifikasi : DomainObject<string>, IHasAssignedId<string>
{
public string Name { get; set; }
public string Description { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public DateTime CreatedDate { get; set; }
public string CreatedBy { get; set; }
public DateTime UpdateDate { get; set; }
public string UpdateBy { get; set; }
public void SetAssignedIdTo(string assignedId)
{
Check.Require(!string.IsNullOrEmpty(assignedId), "assignedId may not be null or empty");
// As an alternative to Check.Require, which throws an exception, the
// Validation Application Block could be used to validate the following
Check.Require(assignedId.Trim().Length == 5, "assignedId must be exactly 5 characters");
ID = assignedId.Trim().ToUpper();
}
public override int GetHashCode()
{
return (GetType().FullName + "|" +
ID + "|" +
Name).GetHashCode();
}
}
}
我在另一个类中使用 Notifikasi 类,但会oNoti.ID = "12";
产生错误:
无法在此上下文中使用属性或索引器,因为 set 访问器不可访问。
有人可以帮我解决这个问题吗?(如果相关,我使用 ORM)。
INotifikasiDao dao = DaoFactory.GetNotifikasiDao();
dao.closeSession();
dao.openSession();
EnterpriseSample.Core.Domain.Notifikasi oNoti = new EnterpriseSample.Core.Domain.Notifikasi();
int no = 1;
oNoti.Name = "ETL Account History";
DateTime startDate = DateTime.Today;
DateTime expiryDate = startDate.AddDays(30);
oNoti.StartDate = startDate;
oNoti.EndDate = expiryDate;
oNoti.Description = "ACC_HIST" + startDate + "Failure";
oNoti.ID = "12"; //this is where the error happens
dao.Update(oNoti);