我是EF的新手,并且首先使用EF代码.只是有一个链接https://code.msdn.microsoft.com/How-to-retrieve-output-e85526ba,它显示了如何首先使用EF db的读输出类型参数.所以有人告诉我如何首先通过EF代码从存储过程中检索输出参数?
如果可能的话,请给我一些小样本代码或将我重定向到相关文章.
谢谢
var outParam = new SqlParameter();
outParam.ParameterName = "TotalRows";
outParam.SqlDbType = SqlDbType.Int;
outParam.ParameterDirection = ParameterDirection.Output;
var data = dbContext.Database.SqlQuery<MyType>("sp_search @SearchTerm, @MaxRows, @TotalRows OUT",
new SqlParameter("SearchTerm", searchTerm),
new SqlParameter("MaxRows", maxRows),
outParam);
var result = data.ToList();
totalRows = (int)outParam.Value;
Run Code Online (Sandbox Code Playgroud) 我正在寻找一种方法来了解如何从控制器调用函数内部指令.我得到了剪辑,但因此我是角度新的,这就是为什么下面的代码流不是很清楚.任何人都想解释代码是如何工作的.谢谢
<map set-fn="setDirectiveFn(theDirFn)"></map>
<button ng-click="directiveFn()">call directive function</button>
scope: { setFn: '&' },
link: function(scope, element, attrs) {
scope.updateMap = function() {
alert('inside updateMap()');
}
scope.setFn({theDirFn: scope.updateMap});
}
function MyCtrl($scope) {
$scope.setDirectiveFn = function(directiveFn) {
$scope.directiveFn = directiveFn;
};
}
Run Code Online (Sandbox Code Playgroud) 我是webapi的新手,并开发了一个小的webapi,它有一些动作并返回我的自定义类,名为Response.
Response班public class Response
{
bool IsSuccess=false;
string Message;
object ResponseData;
public Response(bool status, string message, object data)
{
IsSuccess = status;
Message = message;
ResponseData = data;
}
}
Run Code Online (Sandbox Code Playgroud)
[RoutePrefix("api/customer")]
public class CustomerController : ApiController
{
static readonly ICustomerRepository repository = new CustomerRepository();
[HttpGet, Route("GetAll")]
public Response GetAllCustomers()
{
return new Response(true, "SUCCESS", repository.GetAll());
}
[HttpGet, Route("GetByID/{customerID}")]
public Response GetCustomer(string customerID)
{
Customer customer = repository.Get(customerID);
if (customer == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
} …Run Code Online (Sandbox Code Playgroud) 我对角度有点熟悉.还在学习过程中.使用ng版本1.4.8.所以我想知道如何在服务和工厂中定义构造函数.
这是一个示例服务.现在告诉我如何在服务或工厂中定义构造函数?
angular.module('myApp').service('helloService',function($timeout){
this.sayHello=function(name){
$timeout(function(){
alert('Hello '+name);
},2000);
}
});
angular.module('myApp').controller('TestController',
function(helloService){
helloService.sayHello('AngularJS'); // Alerts Hello AngularJS
});
Run Code Online (Sandbox Code Playgroud) 关于asp.net mvc 中剃刀功能的几个问题。
1)看下面的代码
@helper WelcomeMessage(string username)
{
<p>Welcome, @username.</p>
}
Run Code Online (Sandbox Code Playgroud)
然后你像这样调用它: @WelcomeMessage("John Smith")
@functions{
public string GetSomeString(){
return string.Empty;
}
}
Run Code Online (Sandbox Code Playgroud)
看到有两个剃刀功能。第一个@helper用于声明剃刀函数,第二个用于@functions。所以告诉我 之间有@helper and @functions什么区别?
2) 我们可以在 .cs 代码中声明 razor 函数吗……如果是,那么我们需要遵循任何约定吗?
3)我们可以从剃刀函数返回整数吗
@helper Calculator(int a, int b)
{
@{
var sum = a + b;
}
<b>@sum</b>
}
@Calculator(1, 2)
Run Code Online (Sandbox Code Playgroud)
我们可以将 sum 返回到它的调用环境吗?
我是EF的新手并且首先学习EF代码.我正在寻找一个知识,首先用EF代码映射现有的sql server视图.我用POCO映射了我的视图,但得到了以下错误.
当我尝试从视图中获取数据时,抛出以下错误
附加信息:自创建数据库以来,支持'TestDBContext'上下文的模型已更改.考虑使用Code First Migrations来更新数据库
public class TestDBContext : DbContext
{
public TestDBContext()
: base("name=TestDBContext")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new vwCustomerConfiguration());
}
public DbSet<vwCustomer> vwCustomer { get; set; }
}
public class vwCustomerConfiguration : EntityTypeConfiguration<vwCustomer>
{
public vwCustomerConfiguration()
{
this.HasKey(t => t.CustomerID);
this.ToTable("vwCustomer");
}
}
public class vwCustomer
{
public int CustomerID { get; set; }
public string FirstName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
using (var db = new TestDBContext())
{
var listMyViews …Run Code Online (Sandbox Code Playgroud) 根据我的情况,我需要将此图像的路径/img/product.png存储在 razor 变量中,然后我想在 CSS 文件中使用该 razor 变量。下面的css代码在css文件中
.test{
background: url('/img/product.png') no-repeat scroll 0 0 transparent;
}
Run Code Online (Sandbox Code Playgroud)
所以我使用下面这样的代码,但仍然没有运气
.test{
background: url('@Model.LogoUrl') no-repeat scroll 0 0 transparent;
}
Run Code Online (Sandbox Code Playgroud)
我看到这个帖子http://www.codeproject.com/Articles/171695/Dynamic-CSS-using-Razor-Engine 但我不想按照帖子解决我的问题。所以让我知道如何解决这个问题。谢谢
请参阅以下代码.我知道这样我们可以将自定义数据添加到声明中,但现在的问题是如何读回这些值.说我想读回索赔的价值电子邮件和电子邮件2请告诉我我需要写什么代码来回读索赔电子邮件和电子邮件2的值.
UserManager<applicationuser> userManager = new UserManager<applicationuser>(new UserStore<applicationuser>(new SecurityContext()));
ClaimsIdentity identity = userManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie
var user = userManager.Find(userName, password);
identity.AddClaim(new Claim("Email", user.Email));
identity.AddClaim(new Claim("Email2", user.Email));
Run Code Online (Sandbox Code Playgroud) c# asp.net asp.net-mvc claims-based-identity asp.net-identity
只是从这个链接阅读一篇文章http://weblogs.asp.net/dwahlin/creating-custom-angularjs-directives-part-6-using-controllers
像 ng 新手一样,我很难理解他们的代码示例。告诉我一个例子,人们会在没有控制器的情况下编写指令?
(function() {
var app = angular.module('directivesModule');
app.directive('isolateScopeWithController', function () {
var controller = ['$scope', function ($scope) {
function init() {
$scope.items = angular.copy($scope.datasource);
}
init();
$scope.addItem = function () {
$scope.add();
//Add new customer to directive scope
$scope.items.push({
name: 'New Directive Controller Item'
});
};
}],
template = '<button ng-click="addItem()">Add Item</button><ul>' +
'<li ng-repeat="item in items">{{ ::item.name }}</li></ul>';
return {
restrict: 'EA', //Default in 1.3+
scope: {
datasource: '=',
add: '&',
},
controller: controller, …Run Code Online (Sandbox Code Playgroud) public class HomeController : Controller
{
[Route("Users/about")]
[Route("Users/WhoareWe")]
[Route("Users/OurTeam")]
[Route("Users/aboutCompany")]
public ActionResult GotoAbout()
{
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
我为行动定义了许多路线GotoAbout().
如何在生成动作URL时以编程方式在剃刀页面中创建路径URL home/users/about?