我们专注攀枝花网站设计 攀枝花网站制作 攀枝花网站建设
成都网站建设公司服务热线:400-028-6601

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

linq关系映射(1)-创新互联

linq关系映射(1)

创新互联公司从2013年开始,是专业互联网技术服务公司,拥有项目成都做网站、成都网站建设、成都外贸网站建设网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元谢通门做网站,已为上家服务,为谢通门各地企业和个人服务,联系电话:18982081108

C#的这种entity 很像Annotation java的写法..

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Data.Linq.Mapping;
namespace LinqObject.models
{
    [Table(Name = "Player")]
    public class PlayerInfoVO
    {
                         
        private string name;
        [Column(Name="name")]
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
                         
        private int id;
        [Column(IsPrimaryKey=true,Name="id")]
        public int Id
        {
            get { return id; }
            set { id = value; }
        }
                         
        private int level;
        [Column(Name = "level_id")]
        public int Level
        {
            get { return level; }
            set { level = value; }
        }
        private EntityRef _myLevel;
        [Association(Storage="_myLevel",ThisKey="level_id")]
        public EntityRef _MyLevel
        {
            get { return _myLevel; }
            set { _myLevel = value; }
        }
    }
}

主表:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Data.Linq.Mapping;
namespace LinqObject.models{
    [Table(Name="myLevel")]
    public class MyLevel{
        private int id;
        [Column(IsPrimaryKey=true,Name="id")]
        public int Id
        {
            get { return id; }
            set { id = value; }
        }
        private string name;
        [Column(Name="name")]
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        private EntitySet player;
        [Association(Storage = "player", OtherKey = "Id")]
        public EntitySet Player
        {
            get { return player; }
            set { player = value; }
        }
                     
    }
}

删除 操作 :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LinqObject.models;
namespace LinqObject.mylinq{
    public class ConflictLinq{
        public void updatePlayer(int id, string name) {
            AINYLinq db = new AINYLinq(@"Data Source=AONAUFLY\SQLEXPRESS;Initial Catalog=MyLINQ;User ID=sa;Password=******");
            IQueryable myList = from o in db.myLevel
                        where o.Id == 0 && o.Name == "Aonaufly"
                         select o;
            foreach (var o in myList) {
                Console.WriteLine("Ainy------------------------");
                db.myLevel.DeleteOnSubmit(o);
            }
            Console.WriteLine("detail section finished.");
            Console.ReadLine();
            if (myList.Any())
            {
                Console.WriteLine("The parent is presesnt in the Orders collection.");
                try
                {
                    var ordF = (from o in db.myLevel
                               where o.Id == 0
                                select o).First();
                    db.myLevel.DeleteOnSubmit(ordF);
                    Console.WriteLine(ordF.Name);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.ReadLine();
                }
            }
            else {
                Console.WriteLine("There was no parent in the myLevel");
            }
            try
            {
                db.SubmitChanges();
            }
            catch (Exception e) {
                Console.WriteLine(e.Message);
                Console.ReadLine();
            }
        }
    }
}

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


名称栏目:linq关系映射(1)-创新互联
分享地址:http://mswzjz.cn/article/cddjio.html

其他资讯