Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

EF add object has another object

$
0
0

Hello,

I have an entity "A"  that has foreign key with another entity "B".

but why when I want to add object "A", it is required to enter values for "B" object ?

public EntityA AddEntityA (EntityA_DTO a)
        {
            using (var scope = new TransactionScope())
            {
                var obj = Mapper.Map<EntityA_DTO , EntityA >(a);
                UnitOfWork.EntityA_Repository.Add(obj);
                UnitOfWork.Save(); // Error Here >> 
                scope.Complete();
                return EntityA ;
            }
        }

Error > 

Message = "Cannot insert the value NULL into column 'Name', table 'DataBase.dbo.MyTable'; column does not allow nulls. INSERT fails.\r\nThe statement has been terminated."

The Name column is in Entity B, but I need to add object for Entity A ?

I want to add parent object without child


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>