首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >EF4通过函数导入将NULL插入到SQL Server表

EF4通过函数导入将NULL插入到SQL Server表
EN

Stack Overflow用户
提问于 2011-10-11 22:39:13
回答 1查看 66关注 0票数 0

我有一个复杂类型,具有所有字符串属性

代码语言:javascript
复制
// 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; }
}

我已经完成了一个存储过程的函数导入。下面是存储过程:

代码语言:javascript
复制
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有如下签名:

代码语言:javascript
复制
 CreateProduct(string ID, string Name, string Descritpion);

我这样命名它(作为测试):

代码语言:javascript
复制
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)中的内容时,我得到了以下值:

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-10-11 22:54:28

另一个测试失败了(无关),但导致了问题。不知道为什么,但解决了另一个测试,解决了这个问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7727823

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档