我正在创建软件,用户可以根据旧产品创建新产品.
现在我需要使用Entity Framework进行复制/克隆操作.首先,我开始写这样的:
foreach(sourcedata1 in table1) { ... create new table ... copy data ... create Guid ... add foreach(sourcedata2 in table2) { ... create new table ... copy data ... create Guid ... add ... and so on } }
问题是,这不是一个很好的方法.是否有任何简单的方法克隆信息(除了需要为新行生成的Guid)或者我应该手动复制所有内容?
其他方案
您还可以使用EmitMapper或AutoMapper来复制属性.
如何绑定逗号分隔值的查询字符串参数
http://localhost/Action?ids=4783,5063,5305
Run Code Online (Sandbox Code Playgroud)
一个控制器动作期待一个列表?
public ActionResult Action(List<long> ids)
{
return View();
}
Run Code Online (Sandbox Code Playgroud)
注意! ids
在控制器动作中必须有一个列表(或基于IEnumerable的东西),所以string ids
不被接受作为答案,因为这些参数被传递给许多动作并且将字符串解析为数组会增加不需要的噪声.
假设我有以下数据:
Name Priority
A 3
A 5
B 1
C 1
C 3
C 2
Run Code Online (Sandbox Code Playgroud)
我想获得具有最高优先级的不同名称列表,因此结果如下所示:
Name Priority
A 5
B 1
C 3
Run Code Online (Sandbox Code Playgroud)
我如何使用Linq来做到这一点?
我正在使用jQuery.ajax()连接到我的后端服务.我已经配置了一个error()处理程序和一个statusCode()处理程序.它们都工作正常,但是当我的statusCode处理程序被触发时,错误处理程序也会触发(错误处理程序实际上是先触发).我宁愿这不要发生.我假设这是可能的,而不必破解错误处理程序代码?
我的代码看起来像这样:
$.ajax({
...
error: function(...) {
// process a general type of error here
},
statusCode: {
401: function() {
// process a specific authentication failure
}
}
});
Run Code Online (Sandbox Code Playgroud)
那么当HTTP状态代码为401时,如何避免error()处理程序触发?
谢谢你好好阅读!
我有使用nUnit编写的单元测试,测试结构与Phil Haack的帖子类似
namespace MyNamespace
{
[TestFixture]
public class ClassToTest
{
[TestFixture]
public class MethodToTest
{
[Test]
public void ThrowsArgumentNullException_OnNullIndex()
{
...
}
.. more tests for the method ..
}
[TestFixture]
public class AnotherMethodToTest
{
[Test]
public void ThrowsArgumentNullException_OnNullIndex()
{
...
}
.. more tests for the method ..
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,我对用于对单元测试进行分组的外部类没有定论.我曾尝试过和不[TestFixture]
使用外部和/或内部课程,但总是给我不确定性.
我认为正确的行为应该是从内部类测试中显示单元测试状态.有任何想法吗?
更新
一个丑陋的修复似乎是创建一个外部类的虚拟测试,然后将属性Ignore
放在它上面.
[Test, Ignore]
public void DummyTest()
{
Assert.IsTrue(true);
}
Run Code Online (Sandbox Code Playgroud)
更新2
Channs&Wayne是正确的,外部类只用于分组,因此从类更改为命名空间是最佳解决方案.
我想创建可以与Id一起使用或通过传递jQuery对象的函数.
var $myVar = $('#myId');
myFunc($myVar);
myFunc('myId');
function myFunc(value)
{
// check if value is jQuery or string
}
Run Code Online (Sandbox Code Playgroud)
如何检测传递给函数的参数类型?
注意! 这个问题不一样.我不想传递选择器字符串#id.myClass
.我想像示例中那样传递jQuery对象.
从Gulp.js存储库中遵循示例配方时.我收到一个错误:
[12:27:31] Using gulpfile C:\GH\riot-tag-build\Gulpfile.js
[12:27:31] Starting 'browserify'...
_stream_readable.js:602
var written = dest.write(chunk);
^
TypeError: Object #<Readable> has no method 'write'
at write (_stream_readable.js:602:24)
at flow (_stream_readable.js:611:7)
at _stream_readable.js:579:7
at process._tickCallback (node.js:442:13)
Run Code Online (Sandbox Code Playgroud)
我试图修改源代码以符合我的要求,这是我试图运行的Gulpfile没有运气.
var gulp = require('gulp');
var browserify = require('browserify');
var riotify = require('riotify');
var transform = require('vinyl-transform');
var buffer = require('gulp-buffer');
gulp.task('browserify', function () {
// set up the browserify instance on a task basis
var b = browserify({debug: true});
// transform regular node stream to …
Run Code Online (Sandbox Code Playgroud) 我正在使用以下行,我想使它不区分大小写:
var matches = $(this).find('div > span > div#id_to_find[attributeName ^= "filter"]');
if (matches.length > 0) {
}
Run Code Online (Sandbox Code Playgroud)
我的问题是如何使选择器^=
不区分大小写?也许改为过滤然后一些正则表达式?
有一段时间我一直在讨论这个问题.有一些类似的情况,但解决方案不适用于我的情况.
我有一个方法以字符串格式返回过滤器查询.该方法具有不同数据类型的逻辑,设置正确的值,列名等.
string filterQuery = GetFilterQuery(params);
rows = rows.Where(filterQuery);
Run Code Online (Sandbox Code Playgroud)
我的问题是我Nullable DateTime
在数据库String
中有代码方面的代表.
我尝试过以下查询(String
当前表示可能有误):
"BirthDate.ToString() = \"16.2.2012 22:00:00\""
Run Code Online (Sandbox Code Playgroud)
结果:类型'DateTime?'的方法 无法访问
"BirthDate.Value.ToString() = \"16.2.2012 22:00:00\""
Run Code Online (Sandbox Code Playgroud)
结果:LINQ to Entities无法识别方法'System.String ToString()'方法,并且此方法无法转换为商店表达式.
"BirthDate == null ? 1=1 : (DateTime)BirthDate.ToString() = \"16.2.2012 22:00:00\""
Run Code Online (Sandbox Code Playgroud)
结果:'.' 或'''预期
任何想法如何解决问题?
更新(添加了关于查询生成的更多源代码)
var filterQueries = query.GridFilteringOptions.filters
// remove filters that doesn't have all the required information
.Where(o => o.name != string.Empty && o.value != string.Empty && !string.IsNullOrEmpty(o.type))
// remove filters …
Run Code Online (Sandbox Code Playgroud) 我正在为句子上的最后一个字做一些逻辑.单词由空格或" - "字符分隔.
最简单的方法是什么?
编辑
我可以通过从句子末尾向后移动来做到这一点,但我想找到更好的方法
我们有一个Azure项目的移交.该应用程序稍后将在企业网络中维护,客户现在正在询问Azure使用的端口.
据我所知,控制面板是基本的TCP/IP + HTTP,但发布怎么样?我试过Google,但我发现的只是Web Deploy.
c# ×3
javascript ×3
jquery ×3
linq ×2
ajax ×1
azure ×1
browserify ×1
dynamic-linq ×1
gulp ×1
node.js ×1
nunit ×1
ports ×1
publish ×1
resharper ×1
string ×1
unit-testing ×1