【发布时间】:2022-01-09 06:56:52
【问题描述】:
我试图通过连接到技术服务数据库和过滤供应审计来报告所使用的供应,内部审计我关心的是 ActionNotes,它是一个格式如下的单个长字符串:
New Supplie Mobile added: /n Id: 1/n Name: Bateria /n Stock. 0/n Minimum Stock: 10/n IdSquad: 1/n IdSupplie: 1/n
我已经设法编写了这段代码,它在拆分和过滤我不需要的值后创建了一个字符串数组,结果如下:
private void ImportarServicioTecnico()
{
var auditList = db3.Audit.ToList();
var suppliesList = (from t in auditList where t.ActionNotes.ToLower().Contains("new supplie mobile added") select t).ToList();
foreach (var i in suppliesList)
{
InsumosST o = new InsumosST();
var note = i.ActionNotes;
Debug.WriteLine("Audit ID: " + i.Id.ToString() + " Date: " + i.AuditDate);
string[] lines = Regex.Split(note, "/n");
foreach (var l in lines)
{
var checkstring = l.ToLower();
string actual = l;
if (checkstring.Contains("new supplie mobile added") || checkstring.Contains("description:")) {continue;}
if (checkstring.Contains("stock."))
{
int pos2 = actual.IndexOf(".");
Debug.WriteLine(actual.Substring(pos2 + 1));
continue;
}
int pos = actual.IndexOf(":");
Debug.WriteLine(actual.Substring(pos + 1));
}
}
}
审核 ID:21 日期:15-11-2021 10:43:59 1 细菌 0 1 0 1 1
问题是:是否可以使用此代码从我的数据库模型创建对象? 这是我的模型:
public partial class InsumosST
{
public int id { get; set; }
public string supply { get; set; }
public Nullable<System.DateTime> entrydate { get; set; }
public string squad { get; set; }
}
enter code here
【问题讨论】:
-
是什么阻止您实例化
InsumosST的新实例,然后分配您在foreach循环中解析的值? -
事实上,我为“行”的每个循环只得到一个值,所以如果我创建一个新实例,我只会为对象分配一个值
标签: c# entity-framework linq