HasDatabaseGeneratedOption

HasDatabaseGeneratedOption

本文介绍了获取空引用异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello gyes,

我有两个表fisrt是tblCource,第二个是tblStream和我使用实体框架我的问题关系。



modelBuilder.Entity()

.ToTable(tblCourse)。属性(t => t.Id)

.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)

.HasColumnName(courseid)。HasMany(h => h.Streams)

.WithMany(c => c.Cources)

.Map(m => m.ToTable(tblCourceStream)

.MapLeftKey(courseid)

.MapRightKey(streamid));







modelBuilder.Entity< stream>()

.ToTable(tblStream ).Property(t => t.Id)

.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)

.HasColumnName(streamid);





如何clerly插入,用存储库更新我的记录..

帮我看看...



谢谢&问候

Manamohan



我尝试过:



使用(var ctx = new InstituteContext())

{

var courserepo = new InstituteRepository< cource>(ctx);

var streamrepo = new InstituteRepository< stream>(ctx);

//

var course = courserepo.FindById(2);

var stream = streamrepo.FindById(1);

//

course.Streams.Add(stream);

courserepo.Update(course) ;

//

var save = courserepo.Save();

}

Hello gyes,
I have two table fisrt is tblCource and second is tblStream and i m using entity framework my problem in relationship.

modelBuilder.Entity()
.ToTable("tblCourse").Property(t => t.Id)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
.HasColumnName("courseid").HasMany(h => h.Streams)
.WithMany(c => c.Cources)
.Map(m => m.ToTable("tblCourceStream")
.MapLeftKey("courseid")
.MapRightKey("streamid"));



modelBuilder.Entity<stream>()
.ToTable("tblStream").Property(t => t.Id)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
.HasColumnName("streamid");


How to clerly insert, update my record with repository..
Help me gyes...

Thanks & Regards
Manamohan

What I have tried:

using (var ctx = new InstituteContext())
{
var courserepo = new InstituteRepository<cource>(ctx);
var streamrepo = new InstituteRepository<stream>(ctx);
//
var course = courserepo.FindById(2);
var stream = streamrepo.FindById(1);
//
course.Streams.Add(stream);
courserepo.Update(course);
//
var save = courserepo.Save();
}

推荐答案


这篇关于获取空引用异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 13:09