Tag: sql function

entity framework6代码优先function映射

我想将Entity Framework 6集成到我们的系统中,但是有问题。 我想使用Code First。 出于其他原因,我不想使用Database First * .edmx文件。 我使用属性映射[表],[列],这很好用 数据库有许多用户定义的函数,我需要在Linq To Entities查询中使用它们。 问题是: 我不能通过像[Table],[Column]这样的属性来映射函数。 只有1个属性可用[DbFunction],它需要* .edmx文件。 我可以在* .edmx文件中映射函数,但这意味着我不能使用实体的属性映射:[Table],[Column]。 必须在* .edmx或属性中填充映射。 我尝试通过以下代码创建DbModel并添加函数: public static class Functions { [DbFunction(“CodeFirstNamespace”, “TestEntity”)] public static string TestEntity() { throw new NotSupportedException(); } } public class MyContext : DbContext, IDataAccess { protected MyContext (string connectionString) : base(connectionString, CreateModel()) { } […]

调用标量值函数时,ExecuteScalar始终返回null

为什么这会返回null? //seedDate is set to DateTime.Now; con is initialized and open. Not a problem with that using (SqlCommand command = new SqlCommand(“fn_last_business_date”, con)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue(“@seed_date”, seedDate);//@seed_date is the param name object res = command.ExecuteScalar(); //res is always null } 但是当我直接在DB中调用它时如下: select dbo.fn_last_business_date(‘8/3/2011 3:01:21 PM’) returns ‘2011-08-03 15:01:21.000’ 当我从代码中调用它时,我希望看到的结果 为什么,为什么,为什么?