我有一种情况,当我不能更新数据库中的原始记录,而是创建一个新记录,从旧复制所有字段并将更改应用于新的.(如果翻译成代码,这样的东西)
var original = from _orig in context.Test where _orig.id == 5 select _orig;
Test newTest = new Test();
newTest = original;
newTest.id = 0;
context.Test.InsertOnSubmit(newTest);
context.SubmitChanges();
original.parent_id = newTest.id;
original.isActive = 0;
Run Code Online (Sandbox Code Playgroud)
这给出了以下例外:
Cannot add an entity that already exists.
Run Code Online (Sandbox Code Playgroud)
是否可以在不手动复制每个字段的情况下使其工作?
我在使用EF和AutoMapper时遇到了一些问题.= /
例如 :
我有2个相关实体(客户和订单),他们是DTO课程:
class CustomerDTO
{
public string CustomerID {get;set;}
public string CustomerName {get;set;}
public IList< OrderDTO > Orders {get;set;}
}
class OrderDTO
{
public string OrderID {get;set;}
public string OrderDetails {get;set;}
public CustomerDTO Customers {get;set;}
}
//when mapping Entity to DTO the code works
Customers cust = getCustomer(id);
Mapper.CreateMap< Customers, CustomerDTO >();
Mapper.CreateMap< Orders, OrderDTO >();
CustomerDTO custDTO = Mapper.Map(cust);
//but when i try to map back from DTO to Entity it fails with AutoMapperMappingException.
Mapper.Reset();
Mapper.CreateMap< CustomerDTO …
Run Code Online (Sandbox Code Playgroud) 是否可以使用带有SignedXml的http://www.w3.org/2006/12/xml-c14n11 CanonicalizationMethod?
SignedXml signedXml = new SignedXml(xmlDoc);
signedXml.SignedInfo.CanonicalizationMethod = "http://www.w3.org/2006/12/xml-c14n11";
Run Code Online (Sandbox Code Playgroud)
扔了
System.Security.Cryptography.CryptographicException: Could not create the XML tr
ansformation identified by the URI http://www.w3.org/2006/12/xml-c14n11.
Run Code Online (Sandbox Code Playgroud)
谢谢!
是否可以共享 Google 驱动器“应用程序数据”目录中的文件夹?
我在 SO 上看到了很多类似的问题,但没有一个答案。
当用户开始在最后一行输入时,我正在尝试在表的末尾添加一个新行.viewmodel看起来像这样:
function tableRow(number, ownerViewModel) {
this.number = ko.observable(number);
this.remove = function () { ownerViewModel.tableRows.destroy(this); }
ko.dependentObservable(function () {
var curval = this.number();
var rows = ownerViewModel.tableRows();
if (rows.length > 0) {
if (curval != '' && this == rows[rows.length - 1]) {
ownerViewModel.addNewRow();
}
}
}, this);
}
function tableRowsViewModel() {
var that = this;
this.tableRows = ko.observableArray([]);
this.addNewRow = function () {
this.tableRows.push(new tableRow('', that));
}
this.addNewRow();
}
$(document).ready(function () {
ko.applyBindings(new tableRowsViewModel());
});
Run Code Online (Sandbox Code Playgroud)
这是html:
<table>
<thead>
<tr>
<th> …
Run Code Online (Sandbox Code Playgroud) 你好。我有一个看起来像这样的列表:
public class PagedList<T> : List<T>
{
public PagedList(IEnumerable<T> collection) : base(collection)
{ }
public int TotalItems { get; set; }
public int CurrentPage { get; set; }
public int PageSize { get; set; }
//some other properties
}
Run Code Online (Sandbox Code Playgroud)
并在存储库中用于分页
public PagedList<TEntity> GetPaged(int page)
{
var pagedEntities = some_query;
return pagedEntities.AsPagedList(totalResults, page, pageSize);
}
Run Code Online (Sandbox Code Playgroud)
在ASP MVC视图模型中也使用相同的PagedList进行分页。是否可以使用具有所有属性TotalItems / CurrentPage / ...的Automapper映射此集合?
PagedList<DbItem> dbItems = _repository.GetPages(page);
var viewItems = new PagedList<SomeItemView>();
Mapper.Map(dbItems , viewItems);
Run Code Online (Sandbox Code Playgroud)
谢谢!
在lodash中最简单的解决方案是通过例如'text'字段以值'Item-1-5-2'递归查找数组中的项目?
const data = [
{
id: 1,
text: 'Item-1',
children: [
{ id: 11, text: 'Item-1-1' },
{ id: 12, text: 'Item-1-2' },
{ id: 13, text: 'Item-1-3' },
{ id: 14, text: 'Item-1-4' },
{
id: 15,
text: 'Item-1-5',
children: [
{ id: 151, text: 'Item-1-5-1' },
{ id: 152, text: 'Item-1-5-2' },
{ id: 153, text: 'Item-1-5-3' },
]
},
]
},
{
id: 2,
text: 'Item-2',
children: [
{ id: 21, text: 'Item-2-1' },
{ id: …
Run Code Online (Sandbox Code Playgroud) 我正在尝试在T-SQL中执行计算,但我遇到了一些问题.这是我正在尝试做的事情:
DECLARE @CNT money
SELECT @CNT = 0
Select Amount,
case
when Service like 'pay_in' then SET @CNT = @CNT + Amount
when Service like 'pay_out' then SET @CNT= @CNT - Amount
end
from Payment where isActive = 1
select @CNT
Run Code Online (Sandbox Code Playgroud)
由于我对T-SQL语法知之甚少,我被困在这里,如果有人能够把我推向正确的方向,我将非常感激.谢谢!
将.net类序列化为json并在javascript中使用它的正确方法是什么?
例如在服务器端,我们有这个:
public ActionResult Index()
{
var someClass = new SomeClass { Message = "let's try <b> this </b> and this \" " };
ViewBag.someDataJson = JsonConvert.SerializeObject(someClass);
return View();
}
public class SomeClass
{
public string Message;
}
Run Code Online (Sandbox Code Playgroud)
在客户端:
<script type="text/javascript">
$(document).ready(function() {
var someData = $.parseJSON("@Html.Raw(ViewBag.someDataJson)");
alert(someData.Message);
});
</script>
Run Code Online (Sandbox Code Playgroud)
将导致:
var someData = $.parseJSON("{"Message":"let's try <b> this </b> and this \" "}");
Run Code Online (Sandbox Code Playgroud)
哪个不对.也没有Html.Raw()结果也将是不正确的:
var someData = $.parseJSON("{"Message":"let's try <b> this </b> and this \" "}");
Run Code Online (Sandbox Code Playgroud)
谢谢!
automapper ×2
c# ×2
dto ×1
google-api ×1
javascript ×1
jquery ×1
json ×1
knockout.js ×1
linq-to-sql ×1
lodash ×1
recursion ×1
signedxml ×1
sql-server ×1
t-sql ×1