LINQ时间(7)和时间跨度映射 [英] Linq Time(7) and TimeSpan Mapping

查看:122
本文介绍了LINQ时间(7)和时间跨度映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图插入一条记录,以我的表名为测试,我使用LINQ技术:

I'm trying to insert a record to my table called Test , I'm using the LINQ technique :

问题是我有一个时间列在我的表型的时间(7)但是当我尝试插入数据,以表我得到这个错误:

The problem is I have a time column in my table with type of Time(7) but when I try to insert data to table I get this error :

操作数类型冲突:BIGINT随时间不兼容

这是我的测试在SQL表设计:

this is my test table Design in SQL :

我的在C#中的表执行:

My table Implementation in C# :

[Table(Name = "Test")]
class TableTest
{
    private int _id;
    [Column(IsPrimaryKey = true, Name = "id", Storage = "_id")]
    public int id
    {
        get { return _id; }
        set { _id = value; }
    }
    private TimeSpan _time;
    [Column(Name = "time", Storage = "_time")]
    public TimeSpan time
    {
        get { return _time; }
        set { _time = value; }
    }
}



在这里,我尝试插入我的记录:

and here I try to Insert my Record :

    DataContext dc = new DataContext(@"Data Source=.;Initial Catalog=DBTest;Integrated Security=True");

    private void button1_Click(object sender, EventArgs e)
    {
        TableTest t = new TableTest();
        t.id = 1;
        t.time = new TimeSpan(7, 30, 0);
        Table<TableTest> t_insert = dc.GetTable<TableTest>();
        t_insert.InsertOnSubmit(t);
        dc.SubmitChanges();  // error Here !!!!!
    }



我已经搜查每一个地方,我所发现的是,用于映射时间()我应该使用SQL类型时间跨度,请告诉我,我做错了什么!谢谢

I've searched every where , All I found was that for mapping Time() sql type I should use TimeSpan , please Tell me What I'm doing wrong ! thanks

推荐答案

ColumnAttribute 需要包括的DbType 参数。将其设置为

Your ColumnAttribute needs to include the DbType parameter. Set it to

[Column(Storage="_time", DbType="Time NOT NULL")]

您可以看到更多的的 MSDN

这篇关于LINQ时间(7)和时间跨度映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆