小编myk*_*kyi的帖子

如何将未映射到Linq中的表的字段添加到Sql中

在Entity Framework中,我可以将NotMapped属性应用于我不想在数据库表中创建列的属性.如何在DBML文件中为自动生成的类获得相同的效果?我有一个StoredProcedure返回一些额外的字段.我打电话给SP:

[global::System.Data.Linq.Mapping.FunctionAttribute(Name = "dbo.sp_GetSupplierArticles")]
public ISingleResult<SupplierArticle> GetSupplierArticles([global::System.Data.Linq.Mapping.ParameterAttribute(DbType = "BigInt")] long mainArticleId, [global::System.Data.Linq.Mapping.ParameterAttribute(DbType = "BigInt")] long? userId)
{
    IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), mainArticleId, userId);
    return ((ISingleResult<SupplierArticle>)(result.ReturnValue));
}
Run Code Online (Sandbox Code Playgroud)

必要的字段我添加到分离的部分类中.如果没有任何其他属性,它将返回my的默认值并应用于[Column(IsDbGenerated = false)]已分隔的partial类:

public partial class SupplierArticle
{
    [Column(IsDbGenerated = false)]
    public double Extra { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

所以它一直有效,直到我尝试SupplierArticle使用另一个查询(而不是我的存储过程):

db.LoadOptions = db.GenerateDataLoadOptions(entitiesToInclude);
var query =
    from shoppingCartItem in db.ShoppingCartItems
    where shoppingCartItem.UserId == userId
    select shoppingCartItem;
return query.ToList();
Run Code Online (Sandbox Code Playgroud)

由于LoadOptions(传入entitiesToInclude …

.net c# linq sql-server

15
推荐指数
1
解决办法
1855
查看次数

无法更新asp.net mvc中的cookie

我可以写和读cookie但我不能改变现有cookie的值,它总是有第一个设定值.我发现几乎没有办法可以实现,但没有人工作.这是我的代码:

private void AddPost(string key)
    {
        var context = System.Web.HttpContext.Current;
        var request = context.Request;
        var response = context.Response;

        var cookie = request.Cookies[Constants.PostsViewing];

        if (cookie == null || string.IsNullOrEmpty(cookie.Value))
        {
            response.Cookies.Add(new HttpCookie(Constants.PostsViewing, key)
            {
                Expires = DateTime.Now.AddDays(365)
            });
        }
        else
        {
            if (cookie.Value.Split(';').Contains(key))
            {
                return;
            }

            var v = cookie.Value + ";" + key;

            cookie.Value = v;
            cookie.Expires = DateTime.Now.AddDays(365);
            response.Cookies.Add(cookie);

            // this way also doesn't work
            //cookie.Value = v;
            //response.AppendCookie(cookie);

            // and this
            //response.Cookies[Constants.PostsViewing].Value = v;
            //response.Cookies[Constants.PostsViewing].Expires = DateTime.Now.AddDays(365);
        } …
Run Code Online (Sandbox Code Playgroud)

c# cookies asp.net-mvc

6
推荐指数
1
解决办法
8824
查看次数

ReactJS:渲染动态组件并传递道具

在 DataGridCell 组件中,我需要提供指出哪个组件应该呈现单元格内容的能力。还需要将 props 传递到该组件中。我尝试用下一种方式(简化版)来做到这一点:

import * as React from 'react';
interface IDataGridCellProps {
    data?: any,
    component?: React.Component,
}

export default class DataGridCell extends React.Component<IDataGridCellProps> {
    public render() {
        const Cmp: React.Component<any> = this.props.component as React.Component;
        return (
            <div>
                <Cmp {...this.props.data} />
            </div>
        )
    }
}
Run Code Online (Sandbox Code Playgroud)

我收到下一个错误:TS2604:JSX 元素类型“Cmp”没有任何构造或调用签名

有什么问题以及渲染动态组件的正确方法是什么?

UPD 我使用DataGridCell这样的组件:

<DataGridCell key={indexCell}
                data={profile}
                component={cell.component}
                />
Run Code Online (Sandbox Code Playgroud)

这是一个循环。cell.component在配置中,看起来像这样:component: TextText是我们的组成部分。

UPD 2 所以看起来问题不在于实现,而在于ts-linttypescript。我将组件转换为类型any,现在它可以工作了。更改线路:const Cmp: any = this.props.component; …

javascript typescript reactjs

5
推荐指数
1
解决办法
6145
查看次数

标签 统计

c# ×2

.net ×1

asp.net-mvc ×1

cookies ×1

javascript ×1

linq ×1

reactjs ×1

sql-server ×1

typescript ×1