EF4通过函数导入向SQL Server表插入null
本文关键字:Server 插入 null SQL 函数 导入 EF4 | 更新日期: 2023-09-27 18:10:53
我有一个复杂的类型,所有的字符串属性
// 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)
Supidity,另一个测试失败(不相关),但导致了问题。不知道为什么,但解决了其他测试,解决了这个问题。