我正在导入一些具有多个string字段的记录,从旧数据库到新数据库.它看起来很慢,我怀疑是因为我这样做:
foreach (var oldObj in oldDB)
{
NewObject newObj = new NewObject();
newObj.Name = oldObj.Name.Trim().Replace('^', '?').Replace('@', 'Ž').Replace('[', 'Š')
.Replace(']', '?').Replace('`', 'ž').Replace('}', '?')
.Replace('~', '?').Replace('{', 'š').Replace('\\', '?');
newObj.Surname = oldObj.Surname.Trim().Replace('^', '?').Replace('@', 'Ž').Replace('[', 'Š')
.Replace(']', '?').Replace('`', 'ž').Replace('}', '?')
.Replace('~', '?').Replace('{', 'š').Replace('\\', '?');
newObj.Address = oldObj.Address.Trim().Replace('^', '?').Replace('@', 'Ž').Replace('[', 'Š')
.Replace(']', '?').Replace('`', 'ž').Replace('}', '?')
.Replace('~', '?').Replace('{', 'š').Replace('\\', '?');
newObj.Note = oldObj.Note.Trim().Replace('^', '?').Replace('@', 'Ž').Replace('[', 'Š')
.Replace(']', '?').Replace('`', 'ž').Replace('}', '?')
.Replace('~', '?').Replace('{', 'š').Replace('\\', '?');
/*
... some processing ...
*/
}
Run Code Online (Sandbox Code Playgroud)
现在,我已经通过网络阅读了一些帖子和文章,我已经看到了很多不同的想法.有人说如果我做正则表达式会更好MatchEvaluator,有人说最好保留原样. …
我将EntityFramework与POCO一起使用.
假设我有像这样定义的POCO(简化):
class Class1
{
public int ID;
public int SomeNumber;
}
class Class2
{
public int ID;
public int SomeNumber;
}
class Class3
{
public int ID;
public int SomeNumber;
}
class SomeClass
{
public int ID;
public int? Class1ID;
public Class1 Class1;
public int? Class2ID;
public Class2 Class2;
public int? Class3ID;
public Class3 Class3;
}
Run Code Online (Sandbox Code Playgroud)
我想获取所有SomeClass从数据库中的记录,属于的任何一个Class1,Class2或Class3在那里ClassX.SomeNumber等于一定数目.
我编写了LINQ查询,如下所示:
Database DB = new Database(); // object context
var result = …Run Code Online (Sandbox Code Playgroud) 我使用EntityFramework 4 +生成的POCO 禁用了延迟加载.
假设有一些名为Table1,Table2,Table3和Table4的 SQL表,并假设它们包含一些数据.
让我们假设这些表的简化POCO表示如下所示:
public class Table1
{
public int ID;
public DateTime TableDate;
public int Table2ID;
public Table2 Table2;
public ICollection<Table3> Table3s;
}
public class Table2
{
public int ID;
public string SomeString;
public int Table4ID;
public Table4 Table4;
}
public class Table3
{
public int ID;
public int Table1ID;
public Table1 Table1;
public decimal SomeDecimal;
}
public decimal Table4
{
public int ID;
public string SomeName;
}
Run Code Online (Sandbox Code Playgroud)
如果将执行以下代码:
Database …Run Code Online (Sandbox Code Playgroud) 我一直在关注本教程,以便在我的 WCF 服务中使用传输安全进行用户名身份验证。然而,本教程提到使用basicHttpBinding哪个是不可接受的 - 我需要wsHttpBinding.
这个想法是BasicAuthenticationModule对 WCF 服务进行自定义,该服务将从 HTTP 请求中读取“授权”标头并根据“授权”标头内容执行身份验证过程。问题是缺少“授权”标题!
我已IClientMessageInspector通过自定义行为实现,以便操作传出消息并添加自定义 SOAP 标头。我在BeforeSendRequest函数中添加了以下代码:
HttpRequestMessageProperty httpRequest = request.Properties.Where(x => x.Key == "httpRequest").Single().Value;
httpRequest.Headers.Add("CustomHeader", "CustomValue");
Run Code Online (Sandbox Code Playgroud)
这应该有效,并且根据许多网络资源,它适用于basicHttpBinding但不适用于wsHttpBinding. 当我说“有效”时,我的意思是 WCF 服务成功接收到标头。
这是在 WCF 服务端检查接收到的 HTTP 消息的简化函数:
public void OnAuthenticateRequest(object source, EventArgs eventArgs)
{
HttpApplication app = (HttpApplication)source;
//the Authorization header is checked if present
string authHeader = app.Request.Headers["Authorization"];
if (string.IsNullOrEmpty(authHeader))
{
app.Response.StatusCode = 401;
app.Response.End();
}
}
Run Code Online (Sandbox Code Playgroud)
2011 …
我想从SQL Express 2008 R2服务器返回相对大量的记录,通过EntityFramework 4到WCF服务到WCF客户端.我的测试表目前包含大约11.000条记录.LINQ查询就像这样简单:
Database DB = new Database(); // create object context
var retValue = DB.Entities.Persons
.Include("District")
.Include("District.City")
.Include("District.City.State")
.Include("Nationality")
return retValue.ToList();
Run Code Online (Sandbox Code Playgroud)
这大约需要10秒钟才能完成.
在SQL Server Managament Studio中执行时,相同的SELECT查询所需的时间不到1秒.
在EF中它是否必须缓慢?
linq entity-framework sql-server-2008-r2 entity-framework-4 tolist
我正在为似乎是几个基本操作而苦苦挣扎.
假设我有一个名为Master的课程:
public class Master
{
public Master()
{
Children = new List<Child>();
}
public int Id { get; set; }
public string SomeProperty { get; set; }
[ForeignKey("SuperMasterId")]
public SuperMaster SuperMaster { get; set; }
public int SuperMasterId { get; set; }
public ICollection<Child> Children { get; set; }
}
public class Child
{
public int Id { get; set; }
public string SomeDescription { get; set; }
public decimal Count{ get; set; }
[ForeignKey("RelatedEntityId")]
public RelatedEntity RelatedEntity { …Run Code Online (Sandbox Code Playgroud) c# entity-framework entity-framework-core asp.net-core aspnetboilerplate
我使用Microsoft.Azure.Graphs库连接到Cosmos数据库实例并查询图数据库.
我正在尝试优化我的Gremlin查询,以便只选择我只需要的那些属性.但是,我不知道如何选择从边和顶点中选择哪些属性.
假设我们从这个查询开始:
gremlin> g.V().hasLabel('user').
project('user', 'edges', 'relatedVertices')
.by()
.by(bothE().fold())
.by(both().fold())
Run Code Online (Sandbox Code Playgroud)
这将返回以下内容:
{
"user": {
"id": "<userId>",
"type": "vertex",
"label": "user",
"properties": [
// all vertex properties
]
},
"edges": [{
"id": "<edgeId>",
"type": "edge",
"label": "<edgeName>",
"inV": <relatedVertexId>,
"inVLabel": "<relatedVertexLabel>",
"outV": "<relatedVertexId>",
"outVLabel": "<relatedVertexLabel>"
"properties": [
// edge properties, if any
]
}],
"relatedVertices": [{
"id": "<vertexId>",
"type": "vertex",
"label": "<relatedVertexLabel>",
"properties": [
// all related vertex properties
]
}]
}
Run Code Online (Sandbox Code Playgroud)
现在假设我们只从我们命名为"User"的根顶点获取一些属性:
gremlin> g.V().hasLabel('user').
project('id', 'prop1', 'prop2', 'edges', 'relatedVertices') …Run Code Online (Sandbox Code Playgroud) 我刚刚开始学习 Rust,虽然我确实有一些 C++ 经验(尽管它很生锈),所以我可以理解指针、引用和其他东西,但我似乎无法理解在我尝试它时出现的这个错误。
考虑以下代码:
let mut original = String::from("original value");
{
let next = &mut original;
*next = String::from("next value");
println!("\nInner scope original: \t\"{}\"", original); // <-- error here
println!("\nInner scope next: \t\"{}\"", next);
}
println!("\nOuter original value: \t\"{}\"", original);
Run Code Online (Sandbox Code Playgroud)
编译器抛出错误:
error[E0502]: cannot borrow `original` as immutable because it is also borrowed as mutable
| let next = &mut original;
| ------------- mutable borrow occurs here
| *next = String::from("next value");
| println!("\nInner scope original: \t\"{}\"", original);
| ^^^^^^^^ …Run Code Online (Sandbox Code Playgroud) c# ×4
linq ×2
.net ×1
asp.net-core ×1
gremlin ×1
http-headers ×1
performance ×1
regex ×1
replace ×1
rust ×1
string ×1
t-sql ×1
tolist ×1
wcf ×1