我有一个多项目解决方案。在我的EF 6项目Gilbane,RREM.Data中,我有一个包含表TransactionLog的EF模型。然后,我有一个项目Gilbane.RREM.Logging,其中包含一个函数:
public static void RecordTransaction(string appId, string transactionId, DateTime time, string sourceInterface,
string sourceSystem, string tranId, string response, int interfaceId)
{
using (RREM_GilbaneEntities entities = new RREM_GilbaneEntities())
{
try
{
var transactionLog = new TransactionLog
{
transactionID = transactionId,
created = DateTime.Now,
sourceInterface = sourceInterface,
sourceSystem = sourceSystem,
appID = appId,
GilbaneTransactionID = tranId,
response = response,
sourceIP = null,
SourceID = interfaceId,
};
entities.TransactionLogs.Add(transactionLog);
entities.SaveChanges();
}
catch (Exception ex)
{
LogError(appId, ex.ToString(), "RecordTransaction", transactionId, "", interfaceId, "CommonLibrary");
}
}
最后,我有另一个调用RecordTransaction调用的程序集。我一步一步地看着ReordTransaction执行没有错误。它只是没有在TransactionLog表中放置任何东西!尽管它有一个声明的主键。有什么想法吗?
编辑 - EF类库具有从数据库生成的模型:
public partial class RREM_GilbaneEntities : DbContext
{
public RREM_GilbaneEntities()
: base("name=RREM_GilbaneEntities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public virtual DbSet<ErrorLog> ErrorLogs { get; set; }
public virtual DbSet<TransactionLog> TransactionLogs { get; set; }
public virtual DbSet<transactionController> transactionControllers { get; set; }
public virtual DbSet<TransactionOutgoingQueue> TransactionOutgoingQueues { get; set; }
public virtual DbSet<respons> responses { get; set; }
}
答案 0 :(得分:0)
如果您没有收到错误,那是因为EF正在存储。这是我的猜测。看看你的App_data文件夹,可能里面有一个文件,你可以在那里找到你的记录。
如何解决这个问题:
请确保设置正确的连接字符串。
设置连接字符串名称,其名称与从DbContext类继承的类名称相同。