[英]How to fix "unrecognized guid format"?
i'm getting "unrecognized guid format" error in my asp.net MVC application when i try to select Guid from mysql database.当我尝试从 mysql 数据库中选择 Guid 时,我的 asp.net MVC 应用程序中出现“无法识别的 guid 格式”错误。
var contact_cstm = ctx.contacts_cstm.Where(x => x.national_id_c == model.NID).FirstOrDefault();
if (contact_cstm != null)
{
var contact = ctx.contacts.Where(x => x.id == contact_cstm.id_c && x.deleted==false).FirstOrDefault();
if (contact != null)
{
model.FName = contact.first_name;
}
ctx.SaveChanges();
return true;
}
in contact_cstm I am getting the GUID fine,在 contact_cstm 中,我得到的 GUID 很好,
but in the second query when I use where clause it will show me the error.但是在第二个查询中,当我使用 where 子句时,它会显示错误。
var contact = ctx.contacts.Where(x => x.id == contact_cstm.id_c && x.deleted==false).FirstOrDefault();
My ContactModel我的联系方式
public partial class contact
{
public System.Guid id { get; set; }
public string first_name { get; set; }
public string phone_mobile { get; set; }
}
Stack Trace:堆栈跟踪:
[FormatException: Unrecognized Guid format.]
System.Guid.TryParseGuid(String g, GuidStyles flags, GuidResult& result) +12635324
System.Guid..ctor(String g) +108
MySql.Data.Types.MySqlGuid.MySql.Data.Types.IMySqlValue.ReadValue(MySqlPacket packet, Int64 length, Boolean nullVal) +205
MySql.Data.MySqlClient.NativeDriver.ReadColumnValue(Int32 index, MySqlField field, IMySqlValue valObject) +168
MySql.Data.MySqlClient.ResultSet.ReadColumnData(Boolean outputParms) +65
MySql.Data.MySqlClient.ResultSet.NextRow(CommandBehavior behavior) +158
MySql.Data.MySqlClient.MySqlDataReader.Read() +62
MySql.Data.Entity.EFMySqlDataReader.Read() +13
System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.StoreRead() +36
[EntityCommandExecutionException: An error occurred while reading from the store provider's data reader. See the inner exception for details.]
System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.HandleReaderException(Exception e) +4816212
System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.StoreRead() +49
System.Data.Entity.Core.Common.Internal.Materialization.SimpleEnumerator.MoveNext() +41
System.Data.Entity.Internal.LazyEnumerator`1.MoveNext() +114
System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source) +168
System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__1(IEnumerable`1 sequence) +42
System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.ExecuteSingle(IEnumerable`1 query, Expression queryRoot) +61
System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute(Expression expression) +119
System.Data.Entity.Internal.Linq.DbQueryProvider.Execute(Expression expression) +106
System.Linq.Queryable.FirstOrDefault(IQueryable`1 source) +220
RegaSelfService.BLL.ContactBLL.updateUserIfExist(ContactModel model) in C:\inetpub\wwwroot\Rega_selfService\RegaSelfService\RegaSelfService\BLL\ContactBLL.cs:46
RegaSelfService.Controllers.<login>d__3.MoveNext() in C:\inetpub\wwwroot\Rega_selfService\RegaSelfService\RegaSelfService\Controllers\ContactController.cs:42
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +102
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +64
System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +97
System.Web.Mvc.Async.<>c__DisplayClass8_0.<BeginInvokeAsynchronousActionMethod>b__1(IAsyncResult asyncResult) +17
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32
System.Web.Mvc.Async.<>c__DisplayClass11_0.<InvokeActionMethodFilterAsynchronouslyRecursive>b__0() +58
System.Web.Mvc.Async.<>c__DisplayClass11_2.<InvokeActionMethodFilterAsynchronouslyRecursive>b__2() +228
System.Web.Mvc.Async.<>c__DisplayClass7_0.<BeginInvokeActionMethodWithFilters>b__1(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34
System.Web.Mvc.Async.<>c__DisplayClass3_6.<BeginInvokeAction>b__4() +35
System.Web.Mvc.Async.<>c__DisplayClass3_1.<BeginInvokeAction>b__1(IAsyncResult asyncResult) +100
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
Please try this :请试试这个:
var id_c = new Guid(contact_cstm.id_c);
var contact = ctx.contacts.Where(x => x.id == id_c && x.deleted==false).FirstOrDefault();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.