我在C#程序中有以下PLINQ语句:
foreach (ArrestRecord arrest in
from row in arrestQueue.AsParallel()
select row)
{
Geocoder geocodeThis = new Geocoder(arrest);
writeQueue.Enqueue(geocodeThis.Geocode());
Console.Out.WriteLine("Enqueued " + ++k);
}
Run Code Online (Sandbox Code Playgroud)
这两个arrestQueue和writeQueue是ConcurrentQueues.
什么都没有并行:
geocodeThis.Geocode(),Visual Studio的Thread下拉只是说[ pid ]主线程.它永远不会去任何其他线程.geocodeThis.Geocode().即使我将Pooling = false添加到数据库连接字符串中,为了强制连接不被合并,我也从未看到过多使用过1个连接geocodeThis.Geocode().这看起来像是一个简单的PLINQ案例研究,我正在摸索为什么没有任何东西并行运行.
我在ASP.NET中使用postgreSQL数据库进行项目.我不知道哪种连接类型更好.一方面我在ODBC中有Server Explorer(拖放gridview),另一方面它不是逻辑层的独立应用层.请问哪种连接类型更好ODBC或NpgSQL?为什么?
关于我的项目:
我想使用 Npgsql 将一组键值对作为参数传递给 PostgreSQL 函数。我定义了以下类型:
drop type if exists key_value_pair
create type key_value_pair as (
k varchar(250),
v text
);
Run Code Online (Sandbox Code Playgroud)
我想写一个像这样的函数:
create or replace function persist_profile(
_user_id integer,
_key_value_pairs key_value_pair[]
) returns boolean as $$
begin;
...
return true;
end;
$$ language plpgsql;
Run Code Online (Sandbox Code Playgroud)
如何IDictionary<string, string>使用 Npgsql将数据从对象传递到存储过程?这是支持的吗?我在网上找不到参考。
谢谢!
因此,我正在运行一个简单的选择查询:
Private Function ReturnTableQuery(ByVal SQL As String) As DataTable
Dim rs As DataTable = New DataTable
Dim Adapter As NpgsqlDataAdapter = New NpgsqlDataAdapter
Try
If conn Is Nothing Then
ConnectDatabase()
End If
If conn.State <> ConnectionState.Open Then
ConnectDatabase()
End If
Adapter.SelectCommand = New NpgsqlCommand(SQL, conn)
Adapter.SelectCommand.CommandTimeout = 10
Adapter.Fill(rs)
Catch ex As Exception
PreserveStackTrace(ex)
Throw ex
End Try
Return rs
End Function
Run Code Online (Sandbox Code Playgroud)
SQL命令是:
Select id, application, datetimestamp, status, data, attemptcount from queue where application='reportengine' and status=4 and datetimestamp <= now() …Run Code Online (Sandbox Code Playgroud) 我的代码是这样的,但它给出了一个错误:
//array_field is an array of double values
NpgsqlCommand Command = new NpgsqlCommand("SELECT array_fied from atable");
NpgsqlDataReader dr = Command.ExecuteReader();
while (dr.Read())
{
double[] rrr = dr.GetDouble(dr.GetOrdinal("array_field"));
}
Run Code Online (Sandbox Code Playgroud)
错误消息是:无法将'double'隐式转换为'double []'.我尝试了其他变体,但也没有用.
谢谢你的帮助Judit
我是 Postgres 的新手,我需要连接字符串方面的帮助。
我的应用程序使用实体框架。我有这个连接到 MSSQL 服务器的连接字符串:
<connectionStrings>
<add name="DBContext" connectionString="Data Source=localhost;Initial Catalog=DB;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
在我的项目中,我下载了一个 npgsql 包(http://pgfoundry.org/projects/npgsql/),需要帮助编辑到 Postgres 数据库的连接字符串。
如何将 providerName 设置为 npgsql?
感谢帮助
是否可以使用Npgsql和Entity Framework 6来查询PostgreSQL忽略重音?在Play SQL中,可以使用unaccent扩展,并且可以使用也基于unaccent的索引进行索引:
select * from users where unaccent(name) = unaccent('João')
Run Code Online (Sandbox Code Playgroud)
在以前使用MySql的项目中,我可以使用像utf8_swedish_ci这样的排序规则重音不敏感来解决这个问题,但据我所知,PostgreSQL缺乏这种解决方案.
在安装VS2015 Update 3和Core 1.0版本之后,我试图在ASP.NET Core 1.0 Visual Studio 2015项目中使用PostgreSQL作为用户身份验证的数据存储.
脚步:
创建新的"ASP.NET核心Web应用程序(.NET Framework)"项目.
添加NuGet包"Npgsql"v3.1.4和"Npgsql.EntityFrameworkCore.PostgreSQL"v1.0.0-rc2-release1
修改Startup.cs中的ConfigureServices(),如下所示:
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddEntityFrameworkNpgsql()
.AddDbContext<ApplicationDbContext>(options =>
options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc();
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
}
Run Code Online (Sandbox Code Playgroud)跑
调用AddDbContext()时抛出异常:
MyApp.exe中出现"System.TypeLoadException"类型的异常,但未在用户代码中处理
附加信息:无法从程序集"Microsoft.Extensions.DependencyInjection.Abstractions,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = adb9793829ddae60"加载"Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionExtensions"类型.
我认为这是一个兼容性问题,很快将在Npgsql.EntityFrameworkCore.PostgreSQL中解决,但想确认这一点,并确定是否有可用的解决方法.
我在Ubuntu上使用.NetCore运行npgsql v3.7。
当我执行选择查询并且结果中任何行中的单元格为空时,将引发异常,并显示错误消息“列为空”。
我必须通过将select子句中的每一列放在case语句中测试NULL来解决此问题
"CASE WHEN " + fieldName + " IS NULL THEN '' ELSE " + fieldName + " END "
Run Code Online (Sandbox Code Playgroud)
这似乎有些极端,应该没有必要。还有其他人遇到过这个问题。
谢谢。
我有以下具有必需属性的类,并且遇到通过级联删除删除依赖属性的问题.
public class City
{
[Key]
public int Id {get; private set; }
[Required]
public ZipCode ZipCode { get; private set; }
}
public class ZipCode
{
[Key]
public int Id { get; private set; }
[Required]
public string Zip { get; private set; }
}
Run Code Online (Sandbox Code Playgroud)
如果我尝试加载城市以使用以下代码删除它:
City toDelete = db.CitySet.Where(c => c.Id == myCityReference.Id).FirstOrDefault();
db.CitySet.Remove(toDelete);
db.SaveChanges();
Run Code Online (Sandbox Code Playgroud)
我得到一个Microsoft.EntityFrameworkCore.DbUpdateException,其内在的例外是Npgsql.PostgresException: 23503: Update or delete on table "..." violates foreign key constraint..
但是,如果我在上面添加一个include语句,那就是:
City toDelete = db.CitySet.Include(c => c.ZipCode) …Run Code Online (Sandbox Code Playgroud) npgsql ×10
postgresql ×9
c# ×4
asp.net ×2
.net ×1
ado.net ×1
app-config ×1
arrays ×1
asp.net-mvc ×1
null ×1
odbc ×1
plinq ×1