我在sql中有以下代码:
SET XACT_ABORT ON
Begin Transaction
INSERT INTO TABLE_A VALUES(/*Some Values*/)
INSERT INTO TABLE_B VALUES(/*Some Values*/)
INSERT INTO TABLE_C VALUES(/*Some Values*/)
Update Table Set Values A = A WHERE id = @id /* Some thing like that*/
Commit Transaction
Run Code Online (Sandbox Code Playgroud)
所以,我只是想知道在Insert和Updte语句的Transaction Block中受影响的总行数
我只是想知道,实体框架连接字符串究竟是什么意思?喜欢:
metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=testSource;initial catalog=CatalogName;user id=sa;password=***********;multipleactiveresultsets=True;application name=EntityFramework"
我知道provider = System.Data.SqlClient; provider connection string ="data source = testSource; initial catalog = CatalogName; user id = sa; password =**
谁能告诉我字符串metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;
是什么意思?
而且,还有一件事我需要确认,如果我想在实体连接字符串中编辑,我能做到吗?
我已经OnActionExecuting ActionFilter检查过用户会话是否已过期,如果会话过期,则必须将用户重定向到登录页面.
CompressFilterAttribute.cs文件的代码如下所示:
public override void OnActionExecuting(ActionExecutingContext FilterContext)
{
if (((((System.Web.Mvc.ControllerContext)(FilterContext)).HttpContext).Request).IsAuthenticated)
GZipEncodePage(); //Function to check Session Expiration Time
var action = (string)FilterContext.RouteData.Values["action"];
if (!FilterContext.HttpContext.User.Identity.IsAuthenticated &&
action != "Index" &&
action != "FindStoreNameByText" &&
action.ToLower() != "sessiontimeout" &&
action.ToLower() != "logout")
{
string UrlSucesso = "/Home";
string UrlRedirecionar = string.Format("?ReturnUrl={0}", UrlSucesso);
string UrlLogin = FormsAuthentication.LoginUrl + UrlRedirecionar;
FilterContext.HttpContext.Response.Redirect(UrlSucesso, true);
}
}
Run Code Online (Sandbox Code Playgroud)
CustomErrorHandleAttribute.cs文件的代码如下所示:
public override void OnException(ExceptionContext filterContext)
{
base.OnException(filterContext);
// Rest logic
}
Run Code Online (Sandbox Code Playgroud)
在CustomErrorHandleAttribute.cs …
我陷入了困境,我尝试在网上找到解决方案,但没有成功。我是 MVC 与实体框架的新手,当我尝试运行应用程序时它抛出异常:
传入字典的模型项的类型为“System.Data.Entity.Infrastructure.DbQuery
1[<>f__AnonymousType12[UnRelatedEntity.Models.t_AbortReason,UnRelatedEntity.Models.t_Activity]]”,但该字典需要类型为“UnRelatedEntity.Models”的模型项.MobilePhoneXchangeEntities1'
我使用一个实体作为模型,它分别从两个表中获取数据,它们之间没有关系。
控制器:
public ActionResult Index()
{
MobilePhoneXchangeEntities1 ent = new MobilePhoneXchangeEntities1();
var result = from foo in ent.t_AbortReason
from bar in ent.t_Activity
where foo.AbortReasonCategoryId != null && bar.ActivityId != null
select new { Foo = foo, Bar = bar };
return View(result);
}
Run Code Online (Sandbox Code Playgroud)
看法
@model UnRelatedEntity.Models.MobilePhoneXchangeEntities1
Run Code Online (Sandbox Code Playgroud)
在视图中,我只是在写上面的行,我的意思是我只是继承了模型,没有别的,但我仍然对如何输入模型和模型的类型感到困惑,但我很无助。
任何人都可以为此提供帮助,但请记住,我在我的模型中使用了两个不相关的表。
假设我有一个表,定义如下:
CREATE TABLE Test
(
a INT,
b INT
)
Run Code Online (Sandbox Code Playgroud)
之后,我在表上创建一个视图:
CREATE VIEW ViewTest
AS
SELECT * FROM Test
Run Code Online (Sandbox Code Playgroud)
之后,当我在视图上运行查询时,它会返回两列,即A & B。
并且,稍后我更新表的定义并在其中插入一个新列:
ALTER TABLE Test ADD c INT
Run Code Online (Sandbox Code Playgroud)
但是现在当我运行视图时,它再次返回视图语句,它返回相同数量的列,而不是三列。
我只是想知道为什么?因为我使用了 Select * 语句,所以每次它都应该返回我的整个列。
当我调试我的应用程序时,我发现下面的代码行没有调用我的服务层中的任何方法:
private Lazy<List<userAudit>> lazyList = null;
lazyList = new Lazy<List<userAudit>>(() => client.GetAudit(10).ToList());
Run Code Online (Sandbox Code Playgroud)
而且,我的GetAudit方法将返回审计对象的列表,下面是它的定义:
public List<t_user_audit> GetAudit(int id)
{
return _work.GetGenericRepositoryFor<List<userAudit>>().GetByID(id);
}
Run Code Online (Sandbox Code Playgroud)
并且,在上面的定义中,我在GetAudit方法中插入了一个断点,但是当编译器没有到达断点并且只是将NULL值返回给我时。
我不知道我在哪里犯了错误或者代码有什么问题。
我正在关注您能否解释延迟加载文章。
有人问我,假设我已经在 route.config 中为 URL 定义了路由,并且我已经在基于属性的路由中定义了相同的路由。那么在每种情况下谁的优先级更高。如果我们可以在 route.config 中实现相同的基于属性的路由有什么用。