Id为 uniqueidentifier 默认为 newsequentialid() 插入能返回Id? 返回
CREATE TABLE [dbo].[jobs] (
[Id] uniqueidentifier NOT NULL DEFAULT (newsequentialid()) ROWGUIDCOL ,
[Account] varchar(64) NOT NULL ,
[CreatDate] datetime NOT NULL DEFAULT (getdate())
实体
[Serializable]
public class jobs
{
public Guid id{get;set;}
public string Account { get; set; }
[SugarColumn(IsOnlyIgnoreInsert = true)]
public DateTime CreatDate { get; set; }
}
热忱回答(7)
-
fate stay night VIP0
2018/1/30[SugarColumn(IsOnlyIgnoreInsert = true)]
public Guid id{get;set;}
0 回复 -
月夜-晨风 VIP0
2018/1/30var model = new FZ.Model.jobs() { Account = "qwe123" };
db.Insertable<FZ.Model.jobs>(model).ExecuteReturnEntity();
Response.Write(model.id.ToString());
返回00000000-0000-0000-0000-000000000000
没有取到实体!
0 回复 -
月夜-晨风 VIP0
2018/1/30能不能,插入全局过滤Id字段呀?
0 回复 -
fate stay night VIP0
2018/1/30ExecuteReturnEntity这个是返回自增列,并不能返回你的默认值
0 回复 -
fate stay night VIP0
2018/1/30你这么设计有毛病的, GUID是默认值,我肿么才可以获取到这个GUID呢,显然是不可能获取到,所以GUID还是从程序传
0 回复 -
月夜-晨风 VIP0
2018/1/31namespace SqlSugar
{
public partial class InsertableProvider<T> : IInsertable<T> where T : class, new()
{
/// <summary>
/// mssql 插入返回 Guid的主键Id,支持 newsequentialid() 和 newid()【暴力替换方法,有能力自己修改。】
/// </summary>
/// <returns></returns>
public virtual Guid ExecuteReturnMSGuidId()
{
InsertBuilder.IsReturnIdentity = false;
PreToSql();
AutoRemoveDataCache();
string sql = InsertBuilder.ToSqlString();
//替换字符串、
sql = sql.Replace("VALUES", "OUTPUT INSERTED.[Id] VALUES");
RestoreMapping();
Guid ret = Guid.Empty;
Guid.TryParse(Ado.GetString(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()), out ret);
return ret;
}
}
}
//备注有用的到的方便,
0 回复 -
别烦我\/y VIP0
2022/4/6楼主这个你最后是怎么解决的啊 能不能贴下详细的代码
0 回复