-3

我正在尝试使用 Linq 输入 GUID。我的插入代码:

  var registration = new Registration
            {
                FirstName = registrationInfo.FirstName,
                LastName = registrationInfo.LastName,
                AddressId = _dbcontext.Addresses.Max(x => x.AddressId),
                Password = registrationInfo.Password,
                EmailAddress = registrationInfo.EmailAddress,
                IsActive = true,
                IsDeleted = false,
                Archived=false,
                DateCreated = DateTime.Now
                GUID = ?
            };

任何人都可以帮忙替换“?” 一些有用的代码。

4

3 回答 3

3

使用内置工厂方法创建一个新的:

GUID = Guid.NewGuid()

顺便说一句,二传手AddressId看起来真的很奇怪。如果在两者之间创建了另一个地址,事情就会失败。请改用导航属性。

于 2013-06-17T06:26:59.203 回答
0

取决于您是否需要现有的、空的或新的 Guid,这些选择之一:

Guid.NewGuid();
Guid.Empty;
Guid.Parse("{81a130d2-502f-4cf1-a376-63edeb000e9f}"); // replace with the GUID you need

另请参阅 MSDN 的 GUID 结构:http: //msdn.microsoft.com/en-us/library/cey1zx63.aspx

于 2013-06-17T06:27:34.193 回答
0

试试上面的

 var registration = new Registration
        {
            FirstName = registrationInfo.FirstName,
            LastName = registrationInfo.LastName,
            AddressId = _dbcontext.Addresses.Max(x => x.AddressId),
            Password = registrationInfo.Password,
            EmailAddress = registrationInfo.EmailAddress,
            IsActive = true,
            IsDeleted = false,
            Archived=false,
            DateCreated = DateTime.Now,
            GUID = Guid.NewGuid().ToString()
        };
于 2013-06-17T06:28:00.010 回答