[英]How do I update a table with LINQ-to-SQL without having to delete all the existing records?
[英]How to use Linq-to-SQL without having to generate all the classes?
我之前从未在应用程序中使用过Linq-to-Sql,但我使用LinqPad开发查询,只想将其粘贴到我的代码中。
这不是那么简单。 我猜我需要一个DataContext
来处理连接,但我仍然会收到错误,因为视图名称无法识别。
我是否必须使用设计器并创建所有 View / Table类? 有更简单的方法吗?
这是查询。 不需要任何更新 - 只需这一个查询....
var q = from user in V020
join userapp in V010 on user.SPP_USER_ID equals userapp.SPP_USER_ID
join app in V030 on userapp.SPP_AW_ID equals app.SPP_AW_ID
join tx in V040 on app.SPP_AW_ID equals tx.SPP_AW_ID
join appber in V070 on app.SPP_AW_ID equals appber.SPP_AW_ID
join ber in V050 on appber.SPP_AW_BEREICH_ID equals ber.SPP_AW_BEREICH_ID
where app.SPP_AW_AKTIV && user.SPP_USER_ID == "userid" && tx.SPP_AW_SPR == "de" && ber.SPP_AW_SPR == "de"
orderby ber.SPP_BER_SORTNB
select new {
AppName = app.SPP_AW_KURZBEZ, Url = tx.SPP_AW_URL, Label = tx.SPP_AW_NAME, Description = tx.SPP_AW_BESCHR,
Bereich = ber.SPP_AW_BERNAME,
Owner = app.SPP_AW_VERANTW, Remote = app.SPP_AW_REMOTE
}
;
在EF中,我使用了context.Database.ExecuteSQLCommand来运行存储过程,而不需要使用域模态设计器(因此生成表)。 我相信你可以在Linq to SQL中做类似的事情。 但是,这不支持您拥有的linq查询。 您需要移动存储过程中的所有逻辑。
SiteManagedRepairDetails模型属性:
public long RepairID { get; set; }
public int RepairLineID { get; set; }
DAL方法:
public static int UpsertData(SiteManagedRepairDetails obj)
{
XYZ.DBContexts.VoidsDBContext context = new XYZ.DBContexts.VoidsDBContext();
var results = context.Database.ExecuteSqlCommand("p_XYZDetailsUpsert @RepairID, @RepairLineID"
, new SqlParameter("@RepairID", obj.RepairID)
, new SqlParameter("@RepairLineID", obj.RepairLineID)
);
return 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.