开发者

EF4 inserting NULLs to SQL Server tables via Function Import [closed]

开发者 https://www.devze.com 2023-04-12 19:06 出处:网络
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this po
Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 9 years ago.

Improve this question

I have a complex type, with all string properties

// 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; }
}

I've done a function import of a stored procedure. Here's the stored procedure:

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

My function import has the following signature:

 CreatePr开发者_StackOverflowoduct(string ID, string Name, string Descritpion);

I'm calling it like this (as a test):

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);
}

My problem is, when I look at what's inserted into the database (SQL Server 2008), I'm getting the following values:

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, another test was failing (unrelated), but was causing the issue. Not sure why, but resolving the other test, fixed this problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消