GVKun编程网logo

parent_id外键(自引用),是否为null?

3

此处将为大家介绍关于parent_id外键的详细内容,并且为您解答有关自引用,是否为null?的相关问题,此外,我们还将为您介绍关于angular–currentView.start为nullfull

此处将为大家介绍关于parent_id外键的详细内容,并且为您解答有关自引用,是否为null?的相关问题,此外,我们还将为您介绍关于angular – currentView.start为null fullcalendar、asp.net-mvc – 检查DateTime类型的值在视图中是否为null,如果为null则显示为空、c – 引用不能为NULL,否则为NULL?、c# – 如何检查我的lambda表达式是否为null?的有用信息。

本文目录一览:

parent_id外键(自引用),是否为null?

parent_id外键(自引用),是否为null?

翻阅Bill Karwin的《 QL Antipatterns》一书,第3章,朴素树(邻接表,父子关系),其中有一个注释表的示例。

CREATE TABLE Comments (comment_id SERIAL PRIMARY KEY,parent_id BIGINT UNSIGNED,comment TEXT NOT NULL,FOREIGN KEY (parent_id) REFERENCES Comments(comment_id));

样本数据

| comment_id | parent_id | comments|------------| ----------|-------------------------------------|1           | NULL      |What鈥檚 the cause of this bug?|2           | 1         |I think it''s a null pointer|3           | 2         |No, I checked for that|4           | 1         |We need to check for invalid input|5           | 4         |Yes,that''s a bug|6           | 4         |Yes, please add a check|7           | 6         |That fixed it

该表具有comment_id,parent_id和comment列。parent_id是引用comment_id的外键。

comment_id自动从1开始递增。

问题。

如果假定parent_id是引用comment_id的外键,那么当具有外键的目的是确保引用完整性时,comment_id =
1的行的parent_id为null / 0。

注意:我按原样创建了表格,并尝试输入数据并收到此错误

#1452-无法添加或更新子行:外键约束失败(“ category..comments,CONSTRAINTcomments_ibfk_1FOREIGN KEY(parent_id)参考” commentscomment_id))

答案1

小编典典

从此CW答案的以上评论中收集一些结论。

  • parent_idNULL在此表中为“根”节点,该节点是在树的顶部,并因此没有父。

  • 阅读https://dev.mysql.com/doc/refman/5.7/en/null-values.html:请注意,该NULL值不同于数字类型的值,例如0或字符串类型的空字符串。欲了解更多信息,请参见`[价值](https://dev.mysql.com/doc/refman/5.7/en/problems-with-null.html)[问题NULL`](https://dev.mysql.com/doc/refman/5.7/en/problems-with-null.html)’‘一节。

  • 另请注意,关键字NULL与带有单词的文字字符串不同''NULL''

  • 阅读https://dev.mysql.com/doc/refman/5.7/en/numeric-type-overview.html:在MySQL中,它SERIAL是的别名BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE

angular – currentView.start为null fullcalendar

angular – currentView.start为null fullcalendar

我使用Primeng的计划组件来显示具有计划功能的日历.但我一直得到以下错误:

ORIGINAL EXCEPTION: TypeError: Cannot read property 'clone' of null
ORIGINAL STACKTRACE:
TypeError: Cannot read property 'clone' of null
    at _fetchEventSource (http://localhost:8100/build/js/fullcalendar.js:10703:16)
    at fetchEventSource (http://localhost:8100/build/js/fullcalendar.js:10635:3)
    at fetchEvents (http://localhost:8100/build/js/fullcalendar.js:10629:4)
    at fetchAndRenderEvents (http://localhost:8100/build/js/fullcalendar.js:9789:3)
    at getAndRenderEvents (http://localhost:8100/build/js/fullcalendar.js:9780:4)
    at renderView (http://localhost:8100/build/js/fullcalendar.js:9671:6)
    at initialRender (http://localhost:8100/build/js/fullcalendar.js:9588:3)
    at Calendar_constructor.render (http://localhost:8100/build/js/fullcalendar.js:9552:4)
    at HTMLdivelement.<anonymous> (http://localhost:8100/build/js/fullcalendar.js:53:13)
    at Function.each (http://localhost:8100/build/js/jquery.min.js:2:2813)

在进一步调试时,我发现currentView.start为null,同样设置为rangeStart,这是在fetchEventSource中调用clone的属性.我正在使用defaultview月份.我已经没想完了.请帮帮我.
P.S我正在尝试角度2.我使用的是fullCalendar版本2.7.3. jquery的版本是3.0.0,moment.js的版本是2.13.1.

以下代码导致错误.它是fullCalendar.js的一部分.

function _fetchEventSource(source,callback) {
        var i;
        var fetchers = FC.sourceFetchers;
        var res;

        for (i=0; i<fetchers.length; i++) {
            res = fetchers[i].call(
                t,// this,the Calendar object
                source,rangeStart.clone(),rangeEnd.clone(),options.timezone,callback
            );

            if (res === true) {
                // the fetcher is in charge. made its own async request
                return;
            }
            else if (typeof res == 'object') {
                // the fetcher returned a new source. process it
                _fetchEventSource(res,callback);
                return;
            }
        }
.....

解决方法

我试图包含 angular-ui / fullcalender时遇到了这个问题.这个模块的最后一个版本(1.0.2)依赖于jQuery 2.x并且不能与jQuery 3.x一起使用.根据 this,与jQuery 3一起使用的第一个版本的fullcalender是v2.8.0.

我决定回到jQuery 2.1.4,但如果你需要它,你可以使用
现任主分公司.它在版本2.9.x中使用fullcalender.

希望这可以帮助!

asp.net-mvc – 检查DateTime类型的值在视图中是否为null,如果为null则显示为空

asp.net-mvc – 检查DateTime类型的值在视图中是否为null,如果为null则显示为空

从我的控制器我已经通过值模块来查看

public ActionResult Details(long id,string owner)
    {
        var module = _ownedModuleRepository.GetModuleDetails(id,owner);

        return View(module);
    }

我已经在视图中显示了它包含的值如下

<dt>ID</dt>
    <dd>@Model.Id</dd>

    <dt>Module ID</dt>
    <dd>@Model.ModuleId</dd>

     <dt>Owner</dt>
    <dd>@Model.Owner</dd>

    <dt>Module Type</dt>
    <dd>@Model.TypeName</dd>

    <dt>Module Kind</dt>
    <dd>@Model.KindName</dd>

    <dt>Ownership Start Date</dt>
    <dd>@Model.Start</dd>

    <dt>Ownership End Date</dt>
    <dd>@Model.End</dd>

    @foreach (var properties in Model.Properties)
    {
        <dt>Property Name</dt>
        <dd>@properties.Name</dd>
        <dt>Property Value</dt>
        <dd>@properties.Value</dd>
    }

目前@ Model.End为null,它是DateTime类型,我在viewmodel中将其设置为可为空.
因为它是null,所以这就是我所看到的

如您所见,所有权结束日期的值是从下面获取属性名称的值.如果@ Model.End为null,如何将其设置为空?

编辑1:

我的模特

public class OwnedModuleDetails
{
    public long Id { get; set; }

    public string ModuleId { get; set; }

    public string Owner { get; set; }

    public string KindName { get; set; }
    public string TypeName { get; set; }

    public DateTime Start { get; set; }

    public DateTime? End { get; set; }

    public IEnumerable<Property> Properties { get; set; }
}

来自存储库的方法

public OwnedModuleDetails GetModuleDetails(long id,string owner)
        {
// ReSharper disable ImplicitlyCapturedClosure
            var module = (_dbSis.OwnedModules.Where(t => t.Id == id).Select(m => new OwnedModuleDetails
// ReSharper restore ImplicitlyCapturedClosure
            {
                Id = id,ModuleId = m.ModuleId,TypeName = m.ModuleType.TypeName,KindName = m.ModuleType.ModuleKind.KindName,Owner = owner,Start = m.Start,End = m.End,Properties = m.PropertyConfiguration.PropertyInstances.Select(
                    x => new Property { Name = x.Property.Name,Value = x.Value })
            }));

            return (module.FirstOrDefault());
        }

解决方法

尝试添加空格:

<dt>Ownership End Date</dt>
<dd>
    @if (Model.End != null)
    {
        @Model.End
    }
    else
    {
        @:&nbsp;
    }
</dd>

c – 引用不能为NULL,否则为NULL?

c – 引用不能为NULL,否则为NULL?

我从维基百科读过:

“References cannot be null,whereas pointers can; every reference refers to some object,although it may or may not be valid.”

但是我不相信因为下面的代码看它编译器没有错误:

class person
{
public:
virtual void setage()=0;
};
main()
{
person *object=NULL;
person &object1=*object;
}

请详细说明这一点.

解决方法

说个人&object1 = *对象与说person& object1 = NULL是不一样的.编译器可能不够聪明,无法发现您正在取消引用空指针,反而会出现运行时错误.所以他们是真实的;)

c# – 如何检查我的lambda表达式是否为null?

c# – 如何检查我的lambda表达式是否为null?

如果没有匹配以下lambda查询的记录,我会得到一个

system.invalidOperationException error. Additional information: The cast to value type ‘System.Decimal’ Failed because the materialized value is null. Either the result type’s generic parameter or the query must use a nullable type.

代码是:runTime = db.Records.Where(c => c.MachineDesc.Contains(strMachine)&& c.ProductionDate == dt&& c.Shift == x).Sum(c = > c.RunMinutes);

变量runTime是小数.我尝试将其更改为小数?但我仍然得到同样的错误.

解决这个问题的正确方法是什么?

解决方法

首先,您可以从满足条件的对象中选择十进制值.然后在.Sum()方法之前使用 .DefaultIfEmpty()方法:
runTime = db.Records
              .Where(c => c.MachineDesc.Contains(strMachine) && c.ProductionDate == dt && c.Shift == x)
              .Select(c => c.RunMinutes)
              .DefaultIfEmpty()
              .Sum();

如果序列为空,则DefaultIfEmpty()函数会插入具有默认值的单个元素.而且我们知道,十进制类型的defualt值是0.0M.
(Default Values Table)

另外:

你没告诉我们Linq什么?你正在用吗.但是,如果您使用LinqToEntity,则必须将代码更改为(EF不支持DefaultIfEmpty):

runTime = db.Records
              .Where(c => c.MachineDesc.Contains(strMachine) && c.ProductionDate == dt && c.Shift == x)
              .Sum(c => (decimal?)c.RunMinutes) ?? 0;

今天的关于parent_id外键自引用,是否为null?的分享已经结束,谢谢您的关注,如果想了解更多关于angular – currentView.start为null fullcalendar、asp.net-mvc – 检查DateTime类型的值在视图中是否为null,如果为null则显示为空、c – 引用不能为NULL,否则为NULL?、c# – 如何检查我的lambda表达式是否为null?的相关知识,请在本站进行查询。

本文标签: