我有一个复杂类型,具有所有字符串属性
// Actual class is auto-generated from Model1.tt,
// this is what the class looks like conceptually:
public class Product
{
public string ID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}我已经完成了一个存储过程的函数导入。下面是存储过程:
create procedure [dbo].[CreateProduct]
@ID nvarchar(50),
@Name nvarchar(50),
@Description nvarchar(255)
as
begin tran
insert [dbo].[Products](
ID,
Name,
Description
)
values (
@ID,
@Name,
@Description
)
commit tran
go我的函数import有如下签名:
CreateProduct(string ID, string Name, string Descritpion);我这样命名它(作为测试):
void AddProduct(Product product)
{
entities.CreateProduct(product.ID, product.Name, product.Description);
}
void Test()
{
var now = DateTime.Now.ToString();
var product = new Product
{
ID = string.Format("ID-{0}", now),
Name = string.Format("Name-{0}", now),
Description = string.Format("Description-{0}", now)
}
AddProduct(product);
}我的问题是,当我查看插入到数据库(SQL Server 2008)中的内容时,我得到了以下值:
ID 10/11/2011 10:35:46 AM
Name NULL
Description NULL
// Note, the ID string is not 'ID-10/11/2011 10:35:46 AM' ('ID-' in front)发布于 2011-10-11 22:54:28
另一个测试失败了(无关),但导致了问题。不知道为什么,但解决了另一个测试,解决了这个问题。
https://stackoverflow.com/questions/7727823
复制相似问题