【C# 生成 MongoDB 中的 ID主键唯一】教程文章相关的互联网学习教程文章

尝试使用C#中的Guid作为Cassandra中的主键

我目前正在研究我的NoSQL项目,我有两个数据库Cassandra和Redis(我使用Redis进行缓存).现在使用Redis我有一个列表,我使用DataContract序列化我的自定义对象,但是当涉及到Cassandra时,我正在努力,因为我试图以某种方式在Cassandra表中插入Guid,其中我使用uuid作为主键.我在互联网上搜索过,我所能找到的只是Guid是Cassandra的uuid数据类型.我已经在Cassandra中使用now()插入了uuid所以我想知道我是否可以以某种方式从C#调用now()或者如...

c# – 有没有办法用NHibernate返回插入记录的主键?【代码】

好吧,这个问题有点惹恼了.我现在正在做这样的事情:using (var session = _sessionFactory.OpenSession()) {using (var transaction = session.BeginTransaction()){Car newCar = new Car();newCar.name = "Jeep";session.Save(newCar);transaction.Commit(); } }解决方法: return newCar.Id;当然,在您提交了交易之后.

c# – 两个表oneToMany的FluentNhibernate映射在映射中使用唯一的主键instea【代码】

我正在用C#编写桌面项目.我正在使用Nhibernate与数据库进行通信.此外,我使用FluentNhibernate进行模型映射,但我陷入了映射的某些部分.这是ProductMap中的My mapping Class 松动地图public LosingMap(){Id(x => x.id);Map(x => x.reason);Map(x => x.quantity);Map(x => x.lose_sum);Map(x => x.rate);Map(x => x.deleted);Map(x => x.create_date);Map(x => x.update_date);References(x => x.currency).Column("CurrencyCode");Ta...

C# MySql批量导入 忽略自增主键【代码】

/** 要分两步来处理:1、mysql数据库开启允许本地导入数据的配置,命令如下:SET GLOBAL local_infile=1;//1表示开启,0表示关闭查看该配置的状态命令如下:SHOW VARIABLES LIKE '%local%';2、第二步就是在项目里面的数据库连接字符串做设置数据库连接字符串要加上”AllowLoadLocalInfile=true“如下:const string ConnectionString = "server=localhost;port=3306;user=root;password=123456;database=mysql;SslMode = none;Al...

c# – 如何使用没有主键的SqlAdapter.Update更新表【代码】

我正在使用SqlDataAdapter,我正在更新DataRow. 我有例外Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information如果我将主键放在表中,则会出错. 但我不想把主键放在里面.var dataAdapter = new SqlDataAdapter(); var updatedRows = Getting some row ... dataAdapter.Update(updatedRows);解决方法:如果没有主键,您将无法依赖SqlCommandBuilde...

c# – 使用Linq2Sql使用自动递增的主键将数据插入多个表【代码】

我有一个Customer表,其中包含一个主键(int auto increment)和一个带有Customer表外键的Address表.我试图在一个不错的事务中将两行插入数据库.using (DatabaseDataContext db = new DatabaseDataContext()) {Customer newCustomer = new Customer(){Email = customer.Email};Address b = new Address(){CustomerID = newCustomer.CustomerID,Address1 = billingAddress.Address1};db.Customers.InsertOnSubmit(newCustomer);db.Addr...

c# – Entity Framework 4.0,添加不包含主键的SQL Server视图【代码】

我正在使用Entity Framework 4.0,C#4.0,.Net 2010和SQL Server 2008 R2.我在SQL Server数据库中创建了以下视图:create view viewGetMember as select distinctrow_number() over (order by member.Membership_Number) ID,email.Communication_Point_Id id1,member.Membership_Number Number,dvt.Default_Name ParticipationStatus,person.Given_Name GivenName,person.Last_Name LastName,adrs.House_Number HouseNumber,adrs.St...

c# – 从数据库中检索主键【代码】

是否可以返回数据库中给出的最后一个主键? 这部分是我连接到我的数据库并添加内容的方式,但是如果你需要更多infor请问.public partial class MainWindow : Window {System.Data.SqlClient.SqlConnection con; System.Data.SqlClient.SqlDataAdapter da;DataSet sessions;主要public MainWindow() {InitializeComponent(); }private void button1_Click(object sender, RoutedEventArgs e) {con = new System.Data.SqlClient.SqlCo...

c# – SQLBulkCopy不复制主键【代码】

使用SQLBulkCopy时,处理主键冲突错误的最佳方法是什么Violation of PRIMARY KEY constraint 'email_k__'. Cannot insert duplicate key in object 'lntmuser.email'.(即如果该行已存在于目标表中)? 有没有办法跳过插入重复行或是否必须事先检查和处理? 这是我目前使用的代码:var conPro = tx_ProConStr.Text;var conArc = tx_ArcConStr.Text;var con = new SqlConnection {ConnectionString = conPro};var cmd = new SqlComman...

c# – MVC在数据库中查找不使用主键的行【代码】

假设我有以下课程:public class Item{[Key]public int itemID {get; set;}public int typeID {get; set;} }我知道在数据库中查找记录通常是主键,例如Item item = db.Item.Find(id);如何通过其他列找到记录?即找到typeID = 1的所有记录?解决方法: Item item = db.Items.FirstOrDefault(i => i.typeID == 1);请记住,如果您不使用主键,则可能有多个项目与您的查询匹配.您可以使用上面示例中的FirstOrDefault来获取与查询匹配的第一...