我们有一些使用Linq to SQL作为ORM的遗留代码.我们想将这个逻辑迁移到.Net Core,以便我们可以将它放在Linux服务器上.据我所知,L2S不包含在.Net Core中.
最小阻力的迁移路径是什么?
我正在尝试从SQL Server中提取大型数据集(140万条记录)并转储到WinForms应用程序中的文件.我试图用分页来做这件事,所以我不会立刻在内存中占用太多,但是这个过程会继续增加内存占用量.大约25%通过,它占了600,000K.我在做错分页吗?我可以就如何保持内存使用量不断增长得到一些建议吗?
var query = (from organizations in ctxObj.Organizations
where organizations.org_type_cd == 1
orderby organizations.org_ID
select organizations);
int recordCount = query.Count();
int skipTo = 0;
int take = 1000;
if (recordCount > 0)
{
while (skipTo < recordCount)
{
if (skipTo + take > recordCount)
take = recordCount - skipTo;
foreach (Organization o in query.Skip(skipTo).Take(take))
{
writeRecord(o);
}
skipTo += take;
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试进行概念验证,该概念涉及.Net系统将文件发布到Java Spring Boot应用程序上的Rest端点.我一直收到"必需参数不存在"错误.这个错误有很多SO问题,我尝试过那些没有运气的解决方案.谁能看到我做错了什么?
这是我的C#代码:
private async Task<string> PostFileAsync(string uri, System.IO.FileStream fileStream)
{
using (var client = _httpClientFactory())
{
using (var content = new MultipartFormDataContent())
{
content.Add(new StreamContent(fileStream), "assetFile");
using (var message = await client.PostAsync(uri, content))
{
return await message.Content.ReadAsStringAsync();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是Fiddler看到的请求:
POST http://10.0.2.2:8083/asset/1000/1001 HTTP/1.1
Content-Type: multipart/form-data; boundary="bac9aebd-d9ff-40ef-bcf3-4fffdd1b2c00"
Host: 10.0.2.2:8083
Content-Length: 158
Expect: 100-continue
Connection: Keep-Alive
--bac9aebd-d9ff-40ef-bcf3-4fffdd1b2c00
Content-Disposition: form-data; name=assetFile
foo,bar,10
foo2,bar2,12
--bac9aebd-d9ff-40ef-bcf3-4fffdd1b2c00--
Run Code Online (Sandbox Code Playgroud)
这是我的控制器:
@RestController
@RequestMapping("/asset/")
public class AssetController {
@RequestMapping(path="{merchantId}/{assetId}", method=RequestMethod.POST)
public String getAsset(
HttpServletRequest …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 EF7 实现“软删除”。我的表有一个名为type 的Item字段。我在 SO 和其他地方看到的所有例子都使用这样的东西:IsDeletedbit
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Item>().Map(m => m.Requires("IsDeleted").HasValue(false));
}
Run Code Online (Sandbox Code Playgroud)
但Map()不再是一种方法ModelBuilder。
编辑:让我澄清一下。我现在主要只对读取数据感兴趣。我希望 EF 自动过滤掉我的Item表中 where IsDeleted == 1(或 true)的所有记录。我不想&& x.IsDeleted == false在每个查询的末尾都需要一个。
我正在使用Asp.Net Core和Entity Framework Core开发新的REST API。我们将移植来自使用水平数据库分区(分片)的旧版系统中的数据。我正在尝试一种在EF Core中处理此问题的好方法。我们以前的分片策略涉及一个中央Prime数据库和多个Customer数据库。所有查询都包含一个CustomerId。我们使用CustomerId查询Prime数据库,以确定哪个Customer数据库包含特定客户的数据。数据库模式如下所示:
主数据库
dbo.Database
DatabaseId INTEGER
ConnectionString VARCHAR(200)
dbo.Customer
CustomerId BIGINT
DatabaseId INTEGER
Run Code Online (Sandbox Code Playgroud)
客户数据库
dbo.Order
CustomerId BIGINT
OrderId INT
...
Run Code Online (Sandbox Code Playgroud)
用于获取订单的REST调用示例类似于 http://foo.com/api/Customers/{CustomerId}/Orders/{OrderId}
我需要在CustomerDbContext每个REST请求中使用动态确定的连接字符串。是否应DbContext为每个请求创建新的实例?或者,我可以在运行时更改连接字符串吗?
如果要创建新的DbContext,该如何处理?我可以找到的大多数示例代码都使用Startup.cs中的依赖注入来创建单例DbContext。
.net entity-framework entity-framework-core .net-core asp.net-core