EF4.1 code first 调用存储过程 2种方式

第一种是返回执行结果,

 

 1          ///   <summary>
 2           ///  返回需要的表主键字串
 3           ///  Author:isaac zhang
 4           ///  Date: 2012-04-11
 5           ///   </summary>
 6           ///   <param name="t"> 返回的数据类型typeof([string|int]) </param>
 7           ///   <param name="str"> 前缀:比如TB </param>
 8           ///   <param name="tableName"> 操作的表名称 </param>
 9           ///   <param name="primaryName"> 主键字段 </param>
10           ///   <returns> 需要的主键字串 </returns>
11          public  static  string GetPrimaryKey(Type t,  string str,  string tableName,  string primaryName)
12         {
13              string sql =  " EXECUTE Proc_GetPrimaryKey ' " + str +  " ',' " + tableName +  " ',' " + primaryName +  " ' ";
14              var s = db.Database.SqlQuery(t, sql).Cast< string>().First();
15              return s.ToString();
16         }

第二种返回一个结果集

db.Database.SqlQuery<table>(sql, parameters).ToList();

 

转载于:https://www.cnblogs.com/zhangpan1244/archive/2012/04/11/2442606.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的仓储系统数据库设计,使用 .NET EF Core Code First: ```csharp public class Product { public int Id { get; set; } public string Name { get; set; } public decimal Price { get; set; } public int Quantity { get; set; } public int WarehouseId { get; set; } public Warehouse Warehouse { get; set; } } public class Warehouse { public int Id { get; set; } public string Name { get; set; } public string Address { get; set; } public List<Product> Products { get; set; } } public class Order { public int Id { get; set; } public DateTime OrderDate { get; set; } public int ProductId { get; set; } public Product Product { get; set; } public int Quantity { get; set; } public decimal TotalPrice { get; set; } } public class WarehouseContext : DbContext { public DbSet<Product> Products { get; set; } public DbSet<Warehouse> Warehouses { get; set; } public DbSet<Order> Orders { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=WarehouseDb;Trusted_Connection=True;"); } } ``` 上述代码定义了三个实体类:Product、Warehouse 和 Order,它们分别表示产品、仓库和订单。每个产品都属于一个仓库,一个仓库可以包含多个产品。订单中包含了要购买的产品和数量以及总价。DbContext 包含了三个 DbSet 属性,分别对应这三个实体类的数据库表。在 OnConfiguring 方法中,使用 UseSqlServer 方法指定了数据库连接字符串。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值