When inserting new information, an error occurs. When updating existing information, no problem occurs. There is also no problem when putting the same information into the db without using the code. Test codes do not attempt to store the same information at the same time.
mapping file
<class name="FileInfo" table="update_list" dynamic-update="true" >
<cache usage="read-write"/>
<id name="Name" type="string">
<generator class="native" />
</id>
<property name="Version" />
<property name="pkg" />
<property name="UpdateDate" />
<property name="Size" />
<property name="Path" />
<property name="AutoUpdate" type="TrueFalse" />
</class>
an entity
public class FileInfo
{
public virtual string Name { get; set; }
public virtual string Version { get; set; }
public virtual string pkg { get; set; }
public virtual DateTime UpdateDate { get; set; }
public virtual double Size { get; set; }
public virtual string Path { get; set; }
public virtual bool AutoUpdate { get; set; }
}
saving part
using (var db = Database.Open())
using (var trans = db.BeginTransaction())
{
FileInfo new_file = FileInfoDao.Get(db).GetBypkgName(postedFile.FileName);
if (new_file == null)
{
new_file = new FileInfo();
}
new_file.Name = postedFile.FileName;
new_file.Size = postedFile.ContentLength;
new_file.Path = filePath;
new_file.UpdateDate = DateTime.Now;
new_file.AutoUpdate = true;
var info = apkHelper.GetInfo(filePath);
new_file.pkg = info.Value.Item1;
new_file.Version = info.Value.Item2;
try
{
db.SaveOrUpdate(new_file);
trans.Commit();
}
catch (Exception e)
{
log.Error(e);
}
}