我是Entity Framework 6的新手,我想在我的项目中实现存储过程.我有一个存储过程如下:
ALTER PROCEDURE [dbo].[insert_department]
@Name [varchar](100)
AS
BEGIN
INSERT [dbo].[Departments]([Name])
VALUES (@Name)
DECLARE @DeptId int
SELECT @DeptId = [DeptId]
FROM [dbo].[Departments]
WHERE @@ROWCOUNT > 0 AND [DeptId] = SCOPE_IDENTITY()
SELECT t0.[DeptId]
FROM [dbo].[Departments] AS t0
WHERE @@ROWCOUNT > 0 AND t0.[DeptId] = @DeptId
END
Run Code Online (Sandbox Code Playgroud)
Department 类:
public class Department
{
public int DepartmentId { get; set; }
public string Name { get; set; }
}
modelBuilder
.Entity<Department>()
.MapToStoredProcedures(s =>
s.Update(u => u.HasName("modify_department")
.Parameter(b => b.Department, "department_id")
.Parameter(b => …Run Code Online (Sandbox Code Playgroud) 我有一个ViewModel,它由三个实体连接起来,将所有实体的数据转换为一个视图形式.虽然我成功实现了同样的目标.但我不知道如何编辑和保存数据回数据库.我的模型类由一对一的关系加入.
我的模特是:
public class Doctor
{
public int DoctorId { get; set; }
public string Name { get; set; }
public string Speciality { get; set; }
public virtual DoctorAddress DoctorAddress { get; set; }
public virtual DoctorCharge DoctorCharge { get; set; }
public virtual DoctorAvailablity DoctorAvailablity { get; set; }
}
public class DoctorAddress
{
public string Address { get; set; }
public string City { get; set; }
public int DoctorId { get; set; }
public virtual Doctor …Run Code Online (Sandbox Code Playgroud) 我已经构建了一个查询来从两个表中返回数据,在这两个表中,它们通过内连接加入.虽然,因为查询似乎很好,当我尝试从查询中访问选定的字段名称时,我收到错误消息.我如何在此查询中使用.SingleOrDefault()函数.任何人都可以帮我,我该怎么办.
private void FindByPincode(int iPincode)
{
using (ABCEntities ctx = new ABCEntities())
{
var query = from c in ctx.Cities
join s in ctx.States
on c.StateId equals s.StateId
where c.Pincode == iPincode
select new {
s.StateName,
c.CityName,
c.Area};
// var query = ctx.Cities.AsNoTracking().SingleOrDefault(_city => _city.Pincode == iPincode);
if (query != null)
{
cboState.SelectedItem.Text =query.State; //Getting error "Could not found"
cboCity.SelectedItem.Text = query.CityName; //Getting error "Could not found"
txtArea.Text = query.Area; //Getting error "Could not found"
}
}
}
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我有一个主表名称table1,我mobileNo每天存储或更新数据一个月.
;WITH table1 AS (SELECT * FROM (VALUES
(9999999999, '01/10/2013', NULL, NULL, NULL, NULL),
(9999999999, NULL, '02/10/2013', NULL, NULL, NULL),
(9999999999, NULL, NULL, '03/10/2013', NULL, NULL),
(9999999999, NULL, NULL, NULL, '04/10/2013', NULL),
(9999999999, NULL, NULL, NULL, NULL, '30/10/2013'),
(9999999999, NULL, NULL, NULL, NULL, NULL),
(8888888888, '01/10/2013', NULL, NULL, NULL, NULL),
(8888888888, NULL, '02/10/2013', NULL, NULL, NULL),
(8888888888, NULL, NULL, '03/10/2013', NULL, NULL),
(8888888888, NULL, NULL, NULL, '04/10/2013', NULL),
(8888888888, NULL, NULL, NULL, NULL, '30/10/2013'))
as t(mobileno,date1,date2,date3,date4,date30)) …Run Code Online (Sandbox Code Playgroud) 我有下面给出的代码。我正在尝试将其转换为列表数组。
string str = "1,2,3,4,5,6,7";
var newstring = new int[] {str}; //Cannot implicitly convert type 'string' to 'int'
Run Code Online (Sandbox Code Playgroud)
请帮我。提前谢谢。